// JavaScript Document

var xmlHttp
function sendtoblog(){
	if(document.getElementById("region").value=="")
		alert("Please select Region");
	else if(document.getElementById("destination").value=="")
		alert("Please select Destination");
	else{
			location.href=sendtoblog.arguments[0]+'/'+document.getElementById("destination").value;
		}
}

function filter_blog()
{ 
	if(filter_blog.arguments[0]=="filter"){
		if(document.getElementById("destination").value==0 || document.getElementById("category").value==0)
		{
			alert("Please choose destination/category");	
			return false;
		}		
	location.href="listblog.php?mode=filter&catid="+document.getElementById("category").value+"&did="+document.getElementById("destination").value;
	}
	else{
		location.href="listblog.php";
	}
	
}

function filter_country_destination_filter(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="get_videos.php";

url=url+"?regionid="+str;
xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged2() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("divdestination").innerHTML=xmlHttp.responseText;
}
}

function filter_country_destination(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="get_destination.php";

url=url+"?regionid="+str;
xmlHttp.onreadystatechange=stateChanged1;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged1() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("divdestination").innerHTML=xmlHttp.responseText;
}
}

function filter_destination(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="get_destination.php";

url=url+"?countryid="+str;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("divdestination").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function assign_username(selectObject)
{
	
	document.getElementById("uname").value = selectObject.options[selectObject.selectedIndex].text.toLowerCase();
	

}

function validate_user_studio()
{
	var dm=document.frmstudios;
	var strError="";
	if(dm.uname.value=="")
	strError+="\nUsername";
	if(dm.upwd.value=="")
	strError+="\nPassword";
	if(strError!="")
	{
		alert("Please check the missing field(s)\n=================="+strError);	
		return false;
	}	
}

function validate_country()
{
	var dm=document.frmcountry;
	var strError="";
	if(dm.countryname.value=="")
	strError+="\nCountry name";
	if(dm.regionid.value=="")
	strError+="\nRegion";
	if(strError!="")
	{
		alert("Please check the missing field(s)\n=================="+strError);	
		return false;
	}	
}

function validate_category()
{
	var dm=document.frmcategory;
	var strError="";
	if(dm.category.value=="")
	strError+="\nCategoryname";
	if(dm.description.value=="")
	strError+="\nDescription";
	if(strError!="")
	{
		alert("Please check the missing field(s)\n=================="+strError);	
		return false;
	}	
}

function validate_destination()
{
	var dm=document.frmdestination;
	var strError="";
	if(dm.country.value=="")
	strError+="\nCountry";
	if(dm.destination.value=="")
	strError+="\nDestination";
	if(dm.profilename.value=="")
	strError+="\nProfile Name";

	if(strError!="")
	{
		alert("Please check the missing field(s)\n=================="+strError);	
		return false;
	}	
}

function validate_user()
{
	var dm=document.frmadduser;
	var strError="";
	if(dm.fname.value=="")
	strError+="\nFirstname";
	if(dm.lname.value=="")
	strError+="\nLastname";
	if(emailvalidation(dm.email.value)==false)
	strError+="\nEmail";
	if(dm.uname.value=="")
	strError+="\nUsername";
	if(dm.password.value=="")
	strError+="\nPassword";
	if(dm.repassword.value=="")
	strError+="\nRe-enter Password";
	
	if(dm.password.value!=dm.repassword.value)
	strError+="\nPassword does not match";
	
	if(strError!="")
	{
		alert("Please check the missing field(s)\n=================="+strError);	
		return false;
	}	
}

function emailvalidation(str) {
		
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		  // alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   // alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}


function confirmdelete(){
	if(confirm("Are you sure you want to delete?")){
		location.href=confirmdelete.arguments[0];
	}
}

function validate_gallery(){
	var dm=document.frmgallery;
	var strError="";
	if(dm.title.value=="")
	strError+="\nGallery Title";

	if(strError!="")
	{
		alert("Please check the missing field(s)\n=================="+strError);	
		return false;
	}	
}

function addRow(tableID,fieldtype,fieldsize,fieldname) {  

	 var table = document.getElementById(tableID);  

	 var rowCount = table.rows.length;  
	 var row = table.insertRow(rowCount);  

	 var cell1 = row.insertCell(0);  
	 var element1 = document.createElement("input");  
	 element1.type = "checkbox";  
	 element1.width = "20";
	 cell1.appendChild(element1);  

	 var cell2 = row.insertCell(1);  
	 cell2.innerHTML = rowCount + 1;  

	 var cell3 = row.insertCell(2);  
	 var element2 = document.createElement("input");  
	 element2.type = fieldtype;  
	 element2.size = fieldsize;  
	 element2.name = fieldname;
	 element2.maxlength = 1000;
	 cell3.appendChild(element2);  

 }
 
 function deleteRow(tableID) {  
	 try {  
	 var table = document.getElementById(tableID);  
	 var rowCount = table.rows.length;  
	 for(var i=0; i<rowCount; i++) {  
		 var row = table.rows[i];  
		 var chkbox = row.cells[0].childNodes[0];  

		 if(null != chkbox && true == chkbox.checked) {  
			 table.deleteRow(i);  
			 rowCount--;  
			 i--;  
		 }  

	 }  
	 }catch(e) {  
		 alert(e);  
	 }  
 }
 

function assignimage(){
	var str="",str1,str2="",str3="",str4="";
	var i=0;
	for(i=0; i<document.frm.blogimg.length;i++)
	{
		if(document.frm.blogimg[i].checked){
			str=document.frm.blogimg[i].value;
			str1=str.split(",");
			str2+=str1[0]+",";
			str3+=str1[1]+",";
			str4+="<img src='uploads/"+str1[1]+"'>&nbsp;";
			

		}
	}
	
	str2=str2.substr(0,str2.length-1);
	
	window.opener.document.getElementById("divpimage").innerHTML=str4;
	window.opener.document.getElementById("primaryimage").value=str2;
	
	//str1=str1.substr();
	
	/*if(assignimage.arguments[2]=='p'){
		
		window.opener.document.getElementById("primaryimage").value=assignimage.arguments[0];
		//window.close();
	}
	else
	{
		window.opener.document.getElementById("divsimage").innerHTML="<img src='uploads/thumb_"+assignimage.arguments[1]+"'>";
		window.opener.document.getElementById("secondaryimage").value=assignimage.arguments[0];
		//window.close();
	}
	*/
}

function clearimage()
{
	if(clearimage.arguments[0]=='p'){
		window.opener.document.getElementById("divpimage").innerHTML="";
		window.opener.document.getElementById("primaryimage").value="";
	}
	else
	{
		window.opener.document.getElementById("divsimage").innerHTML="";
		window.opener.document.getElementById("secondaryimage").value="";
	}
}

function selectimage(){
	var dm=document.frmblog.destination.value;
	if(dm=="")
	{
		alert("Please choose the destination first");
		return false;
	}
	else
	{
		var destid=document.frmblog.destination.value;
		var catid=document.frmblog.category.value;
		window.open('selectimage.php?catid='+catid+'&destid='+destid,'','width=600,height=700,left=600,scrollbars=yes'); 
		
	}
}

function changestatus(){
	if(document.frmblog.blogstatus.value=="review")
		document.getElementById("divreviewdetails").style.display="block";
	else
	document.getElementById("divreviewdetails").style.display="none";
	
	
}

function validate_destinationplan(){
	var dm=document.frmdplan;
	var strError="";
	if(dm.country.value=="")
	strError+="\nCountry";
	if(dm.destinationplan.value=="")
	strError+="\nDestination Plan";
	if(dm.lengthofstay.value=="")
	strError+="\nLength of Stay";

	if(strError!="")
	{
		alert("Please check the missing field(s)\n=================="+strError);	
		return false;
	}	
}
	

function favourite_selectimage(){
	var dm=document.frmfavourite.destination.value;
	if(dm=="")
	{
		alert("Please choose the destination first");
		return false;
	}
	else
	{
		var destid=document.frmfavourite.destination.value;
		window.open('selectimage.php?mode='+favourite_selectimage.arguments[0]+'&destid='+destid,'','width=400,height=300'); 
		
	}
}

function validate_blog()
{
	var dm=document.frmblog;
	var strError="";
	if(dm.country.value=="")
	strError+="\nCountry";
	if(dm.destination.value=="")
	strError+="\nDestination";
	if(dm.title.value=="")
	strError+="\nTitle";
	if(dm.desc.value=="")
	strError+="\nDescription";
	
	
	if(strError!="")
	{
		alert("Please check the missing field(s)\n=================="+strError);	
		return false;
	}	
}

function validate_favourite()
{
	var dm=document.frmfavourite;
	var strError="";
	if(dm.title.value=="")
	strError+="\nTitle";
	if(dm.desc.value=="")
	strError+="\nDescription";
	if(dm.country.value=="")
	strError+="\nCountry";
	if(dm.destination.value=="")
	strError+="\nDestination";
	
	if(strError!="")
	{
		alert("Please check the missing field(s)\n=================="+strError);	
		return false;
	}	
}

function validate_news()
{
	var dm=document.frmblog;
	var strError="";
	if(dm.title.value=="")
	strError+="\nTitle";
	if(dm.newstype.value=="")
	strError+="\nNews type";
	if(dm.desc.value=="")
	strError+="\nDescription";
	if(dm.newsdate.value=="")
	strError+="\nDate";
	
	
	if(strError!="")
	{
		alert("Please check the missing field(s)\n=================="+strError);	
		return false;
	}	
}


function validate_password()
{
	var dm=document.frmchangepassword;
	var strError="";
	if(dm.oldpass.value=="")
	strError+="\nOld Password";
	if(dm.newpass.value=="")
	strError+="\nNew Password";
	if(dm.confirmpass.value=="")
	strError+="\nRe-enter Password";
	if(dm.newpass.value!=dm.confirmpass.value)
	strError+="\n Passowrd does not match";
	
	
	if(strError!="")
	{
		alert("Please check the missing field(s)\n=================="+strError);	
		return false;
	}	
}
function owin1(){
		window.open(owin1.arguments[0],'','width=600,height=700,scrollbars=yes');
	}
function owin(){
		window.open(owin.arguments[0],'','width=500,height=400');
	}
	
function openseowindow(){
	window.open(openseowindow.arguments[0],'','width=700,height=500');
	document.getElementById(openseowindow.arguments[1]).style.backgroundColor='#acc0c7';
	}	
	
function checkall(){
	var dm=document.forms["frmprivileges"].elements["chk[]"];
	var str;
	var i;
	if(document.frmprivileges.sellall.checked){
		for(i=0;i<dm.length;i++)
			dm[i].checked=true;
	}else{
		for(i=0;i<dm.length;i++)
			dm[i].checked=false;
		}
}


 function addfaq(tableID) {  

	 var table = document.getElementById(tableID);  

	 var rowCount = table.rows.length;  
	 var row = table.insertRow(rowCount);  

	 var cell1 = row.insertCell(0);  
	 var element1 = document.createElement("input");  
	 element1.type = "checkbox";  
	 cell1.vAlign="top";
	 cell1.appendChild(element1);  
	 
	 var cell2 = row.insertCell(1);  
	 var content='';
	 content+='<table width="100%" cellpadding="3" cellspacing="8">';
     content+='            <TR>  ';
     content+='                    <TD> Name</TD>';
     content+='                    <td><INPUT type="text" size="35" name="name[]"  /></td>';
     content+='           </TR>';
     content+='            <tr>';
     content+='            		<td>Address</TD>  ';
	 content+='             		<td><INPUT type="text" size="35" name="address[]"  /></td>';
     content+='            </TR> ';
     content+='            <tr>';
     content+='            		<td>City</TD>  ';
	 content+='             		<td><INPUT type="text" size="35" name="city[]"  /></td>';
     content+='            </TR> ';
     content+='            <tr>';
     content+='            		<td>Post Code</TD>  ';
	 content+='             		<td><INPUT type="text" size="35" name="postcode[]"  /></td>';
     content+='            </TR> ';

	content+='            <tr>';
     content+='            	<td>Telephone</TD>  ';
	 content+='             <td><INPUT type="text" size="35" name="telephone[]"  /></td>';
     content+='            </TR> ';   
     content+='            <tr>';
     content+='            	<td>Email</TD>  ';
	 content+='             <td><INPUT type="text" size="35" name="email[]"  /></td>';
     content+='            </TR> ';      
     content+='            <tr>';
     content+='            	<td>Website</TD>  ';
	 content+='             <td><INPUT type="text" size="35" name="website[]"  /></td>';
    content+='             </TR>  ';
	cell2.innerHTML = content;			 

 }
 
 function deleteRow(tableID) {  
	 try {  
	 var table = document.getElementById(tableID);  
	 var rowCount = table.rows.length;  
	 for(var i=0; i<rowCount; i++) {  
		 var row = table.rows[i];  
		 var chkbox = row.cells[0].childNodes[0];  

		 if(null != chkbox && true == chkbox.checked) {  
			 table.deleteRow(i);  
			 rowCount--;  
			 i--;  
		 }  

	 }  
	 }catch(e) {  
		 alert(e);  
	 }  
 }  
 
