var openDiv = "";
var height = 320;
var allDialogs = [];
var seq = 0;
var dialog  = "";
function  viewImg(imgId , userId){
			divImg = document.getElementById("mainImg");
			divImg.style.backgroundColor ="#CCCCCC";
			divImg.style.height = "10px";
			if(document.getElementById("imgTbl") ){
				document.getElementById("imgTbl").style.display = "none";
					}
			openDiv = setInterval("openimgDiv()",100);
			//videt
							obj = new AJAX();
							obj.xmlHttp.onreadystatechange=function()
							  {
									if (obj.xmlHttp.readyState==1)
									 { 
										divImg.setAttribute("align","center");
										divImg.style.backgroundColor ="#FFFFFF";
										divImg.innerHTML = '<div align="center" id="plwImg" style="display:block"><br><br><img src="images/lightbox-ico-loading.gif"></div>'; 
									 }
									if (obj.xmlHttp.readyState==4)
									 {  
										 divImg.innerHTML = divImg.innerHTML+obj.xmlHttp.responseText;
										 chkwindowLoad();
									 } 
								}
							url="photos/phAjax.php?op=videt&imgId="+imgId+"&usid="+userId+"&time="+obj.time.getTime();
							obj.xmlHttp.open("GET",url,true);
							obj.xmlHttp.send(null);

	
		}
		
		function openimgDiv(){
			
			divImg = document.getElementById("mainImg");
			cHeight = divImg.offsetHeight;
			//cHeight = cHeight.replace("px","");
			cHeight = eval(cHeight);
			 
			if(cHeight > height)clearTimeout(openDiv);
			else{
					cHeight = cHeight + 10;
					divImg.style.height = cHeight + "px";
				}
			}
timeOutImg = "";
function chkwindowLoad(){
	  
			

			 notYet = -1;
			 imgObject = document.getElementsByTagName("img");

			 for(i=0; i < imgObject.length ; i++){
				 
						 if(imgObject[i].id == "bigImg" ){

							   if(imgObject[i].complete )notYet = 1;
							   else notYet = 0;
							 }
				 								 
					} 
			if(notYet == 1 || notYet == -1  )showTbl();
			else if(notYet == 0)setTimeout("chkwindowLoad()" , 10);
	}

	
	function showTbl(){
		
					tbl    = document.getElementById("imgTbl");
					tbl.style.display = "block";
					clearTimeout(openDiv);
					openDiv = "";
					height = document.getElementById("imgTbl").offsetHeight  ; 
					openDiv = setInterval("openimgDiv()",100);
					
					plw = document.getElementById("plwImg");
					plw.style.display = "none";
			}
	function addComment(userId , rate , imgId){
				 
				if(userId == "")return createNotLogin({draggable: true});
				if(userId != "")return createLogin({draggable: true} ,rate , imgId , userId);
			}
var divIndex =0;
function viewLargeImg(options, imgSrc){
			  
			 
			  options = $.extend({title: "<br> ",modal:true,fixed: false}, options || {});
			  dialog = new Boxy("<div style='display:block' id='wBox"+divIndex+"' align='center'><br><br><br><img src='images/lightbox-ico-loading.gif'></div><div  ><img src='"+imgSrc+"' onload='reMoveWait()'></div>", options);
			  allDialogs.push(dialog);
			  divIndex++;
			  return false;

		
		}
		
		function reMoveWait(){
			divs = document.getElementsByTagName("div");
			for(i = 0 ; i < divs.length; i++){
				if(divs[i].id.indexOf("wBox") > -1 )divs[i].style.display = 'none';
			}

		}
		
  function createNotLogin(options) {
			  options = $.extend({title: "Add Your Comment",modal:true,fixed: false}, options || {});
			  dialog = new Boxy("<div ><table width='300' height='400'><tr><td align='center' class='err'>Kindly Login first</td></tr></table></div>", options);
			  allDialogs.push(dialog);
			  return false;
		  }
function createLogin(options , rate, imgId , userId) {
	
				    options = $.extend({title: "Add Your Comment",modal:true,fixed: false}, options || {});
					table = '<div id="myComCell" style="width:400px; height:300px"><input type="hidden" name="imgi" id="imgi" value="'+imgId+'"><input type="hidden" name="usi" id="usi" value="'+userId+'"><table width="100%"  border="0" cellspacing="0" cellpadding="0">'+
					 '<tr><td width="27%" colspan="2" style="font-size:10px; font-family:Verdana;">Your Comment </td></tr>'+
					 '<tr align="center"><td colspan="2"><textarea name="comm" id="comm" style="width:250px; height:100px "></textarea></td></tr>';
					if(rate == 0)table +='<tr><td>&nbsp;</td><td>&nbsp;</td></tr>';
					else table +='<tr><td class="err" align="center" colspan="2">Your rate was ( '+rate+' ), re-select from the list if you want to edit your rate</td></tr>';
					
					 table +='<tr><td  style="font-size:10px; font-family:Verdana;">Your Rate </td><td>'+
					 '<select name="rate" id="rate" class="DROPDOWN" >';
					 if(rate == 0 )table +='<option value="0" selected>-- Select Rate --</option>';
					 else table +='<option value="0" >-- Select Rate --</option>';

					 if(rate == 1 )table +='<option value="1" selected>1</option>';
					 else table +='<option value="1" >1</option>';

					 if(rate == 2 )table +='<option value="2" selected>2</option>';
					 else table +='<option value="2" >2</option>';

					 if(rate == 3 )table +='<option value="3" selected>3</option>';
					 else table +='<option value="3" >3</option>';

					 if(rate == 4 )table +='<option value="4" selected>4</option>';
					 else table +='<option value="4" >4</option>';

					 if(rate == 5 )table +='<option value="5" selected>5</option>';
					 else table +='<option value="5" >5</option>';

					 table +='</select></td></tr>'+
					 '<tr><td>&nbsp;</td><td>&nbsp;</td></tr>'+
					 '<tr><td colspan="2" align="center"><input type="button" name="Submit" value=" Save " onClick="saveComm()"></td>'+
					 '</tr></table></div>';

				dialog = new Boxy(table, options);
 
				allDialogs.push(dialog);
			    return false;

	
		}	
		
  function createWait(options) {
	
			  options = $.extend({title: "",modal:true,fixed: false}, options || {});
			  dialog = new Boxy("<div  align='center' style='width:300px;height:200px'><br><br><br><img src='images/lightbox-ico-loading.gif'><br>&#46;&#46;&#46;&#1575;&#1604;&#1585;&#1580;&#1575;&#1569;&#32;&#1575;&#1604;&#1571;&#1606;&#1578;&#1592;&#1600;&#1600;&#1575;&#1585;&#32;</div>", options);
			  allDialogs.push(dialog);
			  
			 return false;
		  }
		
function saveComm(){
				textObj1 = document.getElementById("comm");
				textObj2 = document.getElementById("rate");
				imgId    = document.getElementById("imgi").value;
				userId   = document.getElementById("usi").value;
				divCell = document.getElementById("myComCell");
				
				if(! checkTextField(textObj1) ){ alert("Kindly check the comment field");textObj1.focus();
				}else if(textObj2.value == "0"){ alert("Kindly check the rate field");textObj2.focus();
				}else{
					 commTxt = textObj1.value; 
					 commTxt = commTxt.replace("<br>","\n");
								
							obj = new AJAX();
							obj.xmlHttp.onreadystatechange=function()
							  {
									if (obj.xmlHttp.readyState==1)
									 { 
										divCell.innerHTML = "<div  align='center' style='width:300px;height:200px'><br><br><br><img src='images/lightbox-ico-loading.gif'><br>Please Wait...</div>";									 
							  		 }
									if (obj.xmlHttp.readyState==4)
									 {  
									 
										  dialog.hide(); 
										  viewImg(imgId , userId);
										
									 } 
								}
							url="photos/phAjax.php?op=addComRate";
							varsToSend = "imgi="+imgId+"&usId="+userId+"&comT="+commTxt+"&rate="+textObj2.value+"&time="+obj.time.getTime();
							obj.xmlHttp.open("POST",url,true);
							obj.xmlHttp.setRequestHeader("Content-Length", varsToSend.length);
							obj.xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
							obj.xmlHttp.send(varsToSend);
								 
					  
					  }
			// alert(); validation for the comment Form
		}		  
function loadAlbImgs(albumId, userId){
	
	
//	dialog.hide(); 
//	after Getting the data
							createWait({draggable: true});
							obj = new AJAX();
							obj.xmlHttp.onreadystatechange=function()
							  {
									if (obj.xmlHttp.readyState==1)
									 { 
																				 
									 }
									if (obj.xmlHttp.readyState==4)
									 {  
										 document.getElementById("albPh").innerHTML = obj.xmlHttp.responseText;
										 chkwindowLoad2();
									 } 
								}
							url="photos/phAjax.php?op=albImg&albi="+albumId+"&usid="+userId+"&time="+obj.time.getTime();
							obj.xmlHttp.open("GET",url,true);
							obj.xmlHttp.send(null);
		}			
	function chkwindowLoad2(){
	  
			

			 notYet = -1;
			 imgObject = document.getElementsByTagName("img");

			 for(i=0; i < imgObject.length ; i++){
				 
						 if(imgObject[i].id.indexOf("thumb_") > -1 ){

							   if(imgObject[i].complete )notYet = 1;
							   else notYet = 0;
							 }
				 								 
					} 
			if(notYet == 1 || notYet == -1  )dialog.hide(); 
			else if(notYet == 0)setTimeout("chkwindowLoad2()" , 10);
	}	
		function addPhoto(options , albId , userId){
			  options = $.extend({title: "Upload Your Picture",modal:true,fixed: false}, options || {});
			  dialog = new Boxy(document.getElementById("postPh").innerHTML, options);
			  allDialogs.push(dialog);
			}	
