//*****************************************************************************
var xmlhttp = false;
//Check if we are using IE.
try {
//If the Javascript version is greater than 5.
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
//alert ("You are using Microsoft Internet Explorer.");
} catch (e) {
//If not, then use the older active x object.
try {
//If we are using Internet Explorer.
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
//alert ("You are using Microsoft Internet Explorer");
} catch (E) {
//Else we must be using a non-IE browser.
xmlhttp = false;
}
}
//If we are using a non-IE browser, create a javascript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
//alert ("You are not using Microsoft Internet Explorer");
}
//*********
function makerequest(serverPage, objID) {
	
	//alert(serverPage);
var obj = document.getElementById(objID);
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 1){
	obj.innerHTML="<table border=0 align=center cellspacing=0 cellpadding=0 height='100%' ><tr><td align=center><img src='images/loading.gif'></td></tr></table>";
}else if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
	//obj.innerHTML = "3333333333333";
	//alert(xmlhttp.responseText);
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
//*********
//*******************************************************************************


function validate_required(field,div,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {
	  //alert("alerttxt");
	  document.getElementById(div).innerHTML=alerttxt;
	 
	  return false;
	  }
else {
	 document.getElementById(div).innerHTML="";
	return true
}
}
}
function validate_form(thisform)
{
//	var noerror = true;
with (thisform)
{
if (validate_required(title,"titleerror","title must be filled out!")==false)
  {
	  title.focus();/* noerror = false ;*/return false;
  }
if (validate_required(thumb_pic,"thumberror","thumb pic must be filled out!")==false)
  {
	  thumb_pic.focus(); /*noerror = false ;*/return false;
  }
if (validate_required(normal_pic,"normalerror","normal pic must be filled out!")==false)
  {
	  normal_pic.focus(); /*noerror = false ;*/return false;
  }
if (validate_required(summary,"summaryerror","summary must be filled out!")==false)
  {
	  summary.focus();/* noerror = false ;*/return false;
  }
//if(noerror){return true;}

}
} 
//**********************************************************************************************************
function validate_album(thisform)
{
//	var noerror = true;
with (thisform)
{
if (validate_required(albumname,"albumnameerror","name must be filled out!")==false)
  {
	  albumname.focus();/* noerror = false ;*/return false;
  }
if (validate_required(thumb_pic,"thumberror","thumb pic must be filled out!")==false)
  {
	  thumb_pic.focus(); /*noerror = false ;*/return false;
  }

if (validate_required(desc,"descerror","summary must be filled out!")==false)
  {
	  desc.focus();/* noerror = false ;*/return false;
  }
//if(noerror){return true;}

}
} 
//**********************************************************************************************************
function validate_slidesh(thisform)
{
//	var noerror = true;
with (thisform)
{

  if (validate_required(compname,"compnameerror","name must be filled out!")==false)
  {
	  compname.focus();/* noerror = false ;*/return false;
  }
if (validate_required(normal_pic,"normalerror","normal pic must be filled out!")==false)
  {
	  normal_pic.focus(); /*noerror = false ;*/return false;
  }
if (validate_required(desc,"descerror","summary must be filled out!")==false)
  {
	  desc.focus();/* noerror = false ;*/return false;
  }
//if(noerror){return true;}

}
}
//**********************************************************************************************************
//**********************************************************************************************************
function validate_album2(thisform)
{
//	var noerror = true;
with (thisform)
{

  if (validate_required(compname,"compnameerror","name must be filled out!")==false)
  {
	  compname.focus();/* noerror = false ;*/return false;
  }
if (validate_required(thumb_pic,"thumberror","thumb pic must be filled out!")==false)
  {
	  thumb_pic.focus(); /*noerror = false ;*/return false;
  }
if (validate_required(normal_pic,"normalerror","normal pic must be filled out!")==false)
  {
	  normal_pic.focus(); /*noerror = false ;*/return false;
  }
 if (validate_required(album,"albumerror","select album from the list !")==false)
  {
	  album.focus();/* noerror = false ;*/return false;
  }
if (validate_required(desc,"descerror","summary must be filled out!")==false)
  {
	  desc.focus();/* noerror = false ;*/return false;
  }
//if(noerror){return true;}

}
}
//**********************************************************************************************************
function edit_photovideo(thisform)
{
//	var noerror = true;
with (thisform)
{

  if (validate_required(compname,"compnameerror","name must be filled out!")==false)
  {
	  compname.focus();/* noerror = false ;*/return false;
  }

 if (validate_required(album,"albumerror","select album from the list !")==false)
  {
	  album.focus();/* noerror = false ;*/return false;
  }
if (validate_required(desc,"descerror","summary must be filled out!")==false)
  {
	  desc.focus();/* noerror = false ;*/return false;
  }
//if(noerror){return true;}

}
}
//**********************************************************************************************************
function validate_editalbum(thisform)
{
//	var noerror = true;
with (thisform)
{
if (validate_required(albumname,"albumnameerror","name must be filled out!")==false)
  {
	  albumname.focus();/* noerror = false ;*/return false;
  }
if (validate_required(desc,"descerror","summary must be filled out!")==false)
  {
	  desc.focus();/* noerror = false ;*/return false;
  }
//if(noerror){return true;}

}
} 

//**********************************************************************************************************
function validate_edit_form(thisform)
{
//	var noerror = true;
with (thisform)
{
if (validate_required(title,"titleerror","title must be filled out!")==false)
  {
	  title.focus();/* noerror = false ;*/return false;
  }

if (validate_required(summary,"summaryerror","summary must be filled out!")==false)
  {
	  summary.focus();/* noerror = false ;*/return false;
  }
//if(noerror){return true;}

}
}
//*************************************************
function showOrHide(value) {
    if (value==0) {
            document.all['layer1'].style.visibility='hidden';
   }
   else if (value==1) {
          document.all["layer1"].style.visibility='show';
   }
}
function showOrHide2(value) {
    if (value==0) {
            document.all['layer2'].style.visibility='hidden';
   }
   else if (value==1) {
          document.all["layer2"].style.visibility='show';
   }
}
///****************************************************************
function onmouseshow(value,v,oevent){
		if(v==1){
			
			document.getElementById('showimg').innerHTML=document.getElementById('showimg1').innerHTML;
			document.getElementById('img').src=value.id;
			document.getElementById('img').width=100;
			document.getElementById('img').height=100;
			document.getElementById('showimg').style.left=oevent.clientX ;
		  	document.getElementById('showimg').style.top=oevent.clientY;
			//alert(oevent.clientY);
			//alert(oevent.clientX);
			
		
		
		}else{
			
			document.getElementById('showimg').innerHTML="";
		}
	}
	

	//************************************************************
	
function submitform(){
	var ck =  check();
	if(ck){
		var type ="research";
		token =document.commentform.token.value;
		name =document.commentform.nam.value;
		email =document.commentform.email.value;
		comment =document.commentform.comment.value;
		address =document.commentform.address.value;
		//alert("comment.php?token="+token+"&type="+type+"&name="+name+"&email="+email+"&comment="+comment+"&address="+address);
		makerequest("comment.php?token="+token+"&type="+type+"&name="+name+"&email="+email+"&comment="+comment+"&address="+address, 'comm')
		//document.commentform.submit();
		}
}
	//*******************************************
	function submitrat(){
	var ck =  check();
	if(ck){
		var type ="video";
		token =document.commentform.token.value;
		albu =document.commentform.albu.value;
		name =document.commentform.nam.value;
		email =document.commentform.email.value;
		comment =document.commentform.comment.value;
		address =document.commentform.address.value;
		//alert("comment.php?token="+token+"&type="+type+"&name="+name+"&email="+email+"&comment="+comment+"&address="+address);
		makerequest("comment.php?token="+token+"&type="+type+"&name="+name+"&email="+email+"&comment="+comment+"&address="+address+"&album="+albu, 'zzx')
		//document.commentform.submit();
		}
}
	//*******************************************
function check(){
                    email=document.commentform.email.value;
                    comment=document.commentform.comment.value;
					name=document.commentform.nam.value;
                    
                    if(email==''){
                      alert('please insert your e-mail !!');
                      return false;
                    }
                    
                    ar=email.split("@");      
      
                   if(ar.length!=2){
                       alert("please check emial syntax [must be like someone@example.com] !!");
                       return false;
                      }
      
                   ar2=email.split(".");      
                   if(ar2.length<2){
                      alert("please check emial syntax [must be like someone@example.com] !!");
                      return false;
                     } 
                    if(name==''){
                      alert('please insert your name !!');
                      return false;
                    }
                    if(comment==''){
                      alert('please insert your comment !!');
                      return false;
                    }

                    return true;
                  }
				  function chkcommentlength(){
				  comment=document.commentform.commentbox.value.length;
				  if(comment >500){
				  alert('comment must be less than 500 words');
				  return false;
				  }
				  return true;
				  }
//**************************************
function showcomm(value,oevent) {

    if (value==0) {
            document.all['comm'].style.visibility='hidden';
			 document.all['bod'].style.visibility='hidden';
			
   }
   else if (value==1) {
	   	  document.all['bod'].style.visibility='visible';
	   	  document.getElementById('bod').style.width=document.getElementById('f').width;
		  document.getElementById('bod').style.height=document.getElementById('f').height;
		
		  
          document.getElementById('comm').style.visibility='visible';
		  document.getElementById('comm').style.left=oevent.clientY - 150;
		  document.getElementById('comm').style.top=oevent.clientX - 250;
   }
}
//*************************************************************************
function showpopup(value,oevent) {
    if (value==0) {
			document.getElementById('popup').style.visibility='hidden';
            
			 //document.all['bod'].style.visibility='hidden';
			
   }
   else if (value==1) {
	   	  //document.all['bod'].style.visibility='visible';
	   	  //document.getElementById('bod').style.width=document.getElementById('f').width;
		  //document.getElementById('bod').style.height=document.getElementById('f').height;
		
		  
          document.getElementById('popup').style.visibility='visible';
		  document.getElementById('popup').style.left=oevent.clientY - 150;
		  document.getElementById('popup').style.top=oevent.clientX - 250;
		  
   }
}

//*************************************************************************
function chkvote(){
	
	 q=document.voteform.qustion.value;
     f=document.voteform.first.value;
     s=document.voteform.second.value;
	 t=document.voteform.third.value;
	 if(q==''){
     	alert('please insert vote qustion');
     	return false;
     }
	 if(f==''){
     	alert('please insert first vote choise');
     	return false;
     }
	 if(s==''){
     	alert('please insert second vote choise');
     	return false;
     }
	 if(t==''){
     	alert('please insert third vote choise');
     	return false;
     }
	 return true;
}
//***********************************************************************
function subvot (){
//alert ("Button  is selected");

    //for (Count = 0; Count < 3; Count++) {
	//alert (Count);
	
		var type ="vote";
		token =document.vform.token.value;
		if (document.vform.rad[0].checked){
            count = "ch1";
			t=1;
			}else
		if (document.vform.rad[1].checked){
            count = "ch2";
			t=1;
			}else
		if (document.vform.rad[2].checked){
            count = "ch3";
			t=1;
			}else {
            count = "non";
			t=0;
			}
			if(t==1){
				
				makerequest("vote.php?token="+token+"&type="+type+"&vot="+count,"votdiv");
				
				
				//window.open("vote.php?token="+token+"&type="+type+"&vot="count","MyWindow","toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no,width=425,height=385"); return false;"
				
			}
   
	//} 
	
    
}
//***********************************************************************
function ratvot (token){
	alert("d");
//makerequest("rate.php?rat="+rat+"&token="+token,"ratdiv");

}