function GetXmlHttpObject()
{ 
	var objXMLHttp=null
		if (window.XMLHttpRequest)
		{
		objXMLHttp=new XMLHttpRequest()
		}
		else if (window.ActiveXObject)
		{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
	return objXMLHttp
}

var xmlHttp;
var action;

function validateRegForm(){

	if(document.getElementById("name").value ==''){
		alert("Please enter name");
		document.getElementById("name").focus();
		return false;
	}
	if(document.getElementById("email").value ==''){
		alert("Please enter email");
		document.getElementById("email").focus();
		return false;
	}
	if (echeck(document.getElementById("email").value)==false){
		document.getElementById("email").value ='';
		document.getElementById("email").focus()
		return false;
	}
	if(document.getElementById("telephone").value ==''){
		alert("Please enter Mobile Number");
		document.getElementById("telephone").focus();
		return false;
	}
	if(document.getElementById("password").value ==''){
		alert("Please enter password");
		document.getElementById("password").focus();
		return false;
	}
	if(document.getElementById("confirm_password").value ==''){
		alert("Please enter confirm password");
		document.getElementById("confirm_password").focus();
		return false;
	}
	if(document.getElementById("password").value!=document.getElementById("confirm_password").value){
		alert("Password mismatch");
		document.getElementById("confirm_password").value='';
		document.getElementById("confirm_password").focus();
		return false;
	}
	register('g');
	return true;
}


function validateRegForm_m(){
if(document.getElementById("name_m").value ==''){
		alert("Please enter name");
		document.getElementById("name_m").focus();
		return false;
	}
	if(document.getElementById("email_m").value ==''){
		alert("Please enter email");
		document.getElementById("email_m").focus();
		return false;
	}
	if (echeck(document.getElementById("email_m").value)==false){
		document.getElementById("email_m").value ='';
		document.getElementById("email_m").focus()
		return false;
	}
	if(document.getElementById("telephone_m").value ==''){
		alert("Please enter Mobile Number");
		document.getElementById("telephone_m").focus();
		return false;
	}
	if(document.getElementById("password_m").value ==''){
		alert("Please enter password");
		document.getElementById("password_m").focus();
		return false;
	}
	if(document.getElementById("confirm_password_m").value ==''){
		alert("Please enter confirm password");
		document.getElementById("confirm_password_m").focus();
		return false;
	}
	if(document.getElementById("password_m").value!=document.getElementById("confirm_password_m").value){
		alert("Password mismatch");
		document.getElementById("confirm_password_m").value='';
		document.getElementById("confirm_password_m").focus();
		return false;
	}
	register('m');
	return true;
}


/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(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 loginForm(){
	
	document.getElementById('reglogin').innerHTML='<div id="loginn1"><form name="frmlogin" id="frmlogin" method="post"><table width="100%" cellpadding="3" cellspacing="3" align="left"><tbody style="border:none;"><tr><td colspan="2" class="mandatory" id="warning" align="center"></td></tr><tr><td>Email:</td><td><input type="text" name="email" id="email" value="" /><span class="mandatory">*</span></td></tr><tr><td>Password:</td><td><input type="password" name="password" id="password" value="" /><span class="mandatory">*</span></td></tr><tr><td></td><td></td></tr><tr><td></td><td><input type="button" name="submit" id="submit" value="Login" onClick="return validateloginfrm();" /></td></tr><tr><td align"left"><a href="javascript:void(0);" onclick="passwwordReset();">Forgot Password?</a></td><td align"right"><a href="javascript:void(0);" onclick="showRegForm();">Back to Registration</a></td></tr></tbody></table></form></div>';
	
}

function loginForm1(){
	document.getElementById('reglogin').innerHTML='';
	document.getElementById('member_register').innerHTML='<form name="frmlogin" id="frmlogin" method="post"><table width="100%" cellpadding="3" cellspacing="3" align="left"><tbody style="border:none;"><tr><td colspan="2" class="mandatory" id="warning_m" align="center"></td></tr><tr><td>Email:</td><td><input type="text" name="email" id="email" value="" /><span class="mandatory">*</span></td></tr><tr><td>Password:</td><td><input type="password" name="password" id="password" value="" /><span class="mandatory">*</span></td></tr><tr><td></td><td></td></tr><tr><td></td><td><input type="button" name="submit" id="submit" value="Login" onClick="return validateloginfrm(1);" /></td></tr><tr><td align"left"><a href="javascript:void(0);" onclick="passwwordReset1();">Forgot Password?</a></td><td align"right"><a href="javascript:void(0);" onclick="showRegForm1();">Back to Registration</a></td></tr></tbody></table></form>';
	//document.getElementById('loginn1').innerHTML='';
	
}


function showRegForm(){
	document.getElementById('reglogin').innerHTML='<form name="frmregister" id="frmregister" method="post"><table width="100%" cellpadding="3" cellspacing="3" align="left"><tbody style="border:none;"><tr><td colspan="2">Please register with us to see our photos</td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td colspan="2" class="mandatory" id="warning" align="center"></td></tr><tr><td>Name:</td><td><input type="text" name="name" id="name" value=""><span class="mandatory">*</span></td></tr><tr><td>Email:</td><td><input type="text" name="email" id="email" value=""><span class="mandatory">*</span></td></tr><tr><td>Mobile:</td><td><input type="text" name="telephone" id="telephone" value=""><span class="mandatory">*</span></td></tr><tr><td>Password:</td><td><input type="password" name="password" id="password" value=""><span class="mandatory">*</span></td></tr><tr><td>Confirm Password:</td><td><input type="password" name="confirm_password" id="confirm_password" value=""><span class="mandatory">*</span></td></tr><tr><td></td><td></td></tr><tr><td></td><td><input type="button" name="submit" id="submit" value="Register" onClick="return validateRegForm();"></td></tr><tr><td></td><td></td></tr><tr><td colspan="2"><a href="javascript:void(0);" onclick="loginForm();">Already registered? Please click here to login</a></td></tr></tbody></table></form>';
}

function showRegForm1(){
	document.getElementById('member_register').innerHTML='<form name="frmregister" id="frmregister" method="post"><table width="100%" cellpadding="3" cellspacing="3" align="left"><tbody style="border:none;"><tr><td colspan="2">Please register with us to see our photos</td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td colspan="2" class="mandatory" id="warning_m" align="center"></td></tr><tr><td>Name:</td><td><input type="text" name="name_m" id="name_m" value=""><span class="mandatory">*</span></td></tr><tr><td>Email:</td><td><input type="text" name="email_m" id="email_m" value=""><span class="mandatory">*</span></td></tr><tr><td>Mobile:</td><td><input type="text" name="telephone_m" id="telephone_m" value=""><span class="mandatory">*</span></td></tr><tr><td>Password:</td><td><input type="password_m" name="password_m" id="password_m" value=""><span class="mandatory">*</span></td></tr><tr><td>Confirm Password:</td><td><input type="password" name="confirm_password_m" id="confirm_password_m" value=""><span class="mandatory">*</span></td></tr><tr><td></td><td></td></tr><tr><td></td><td><input type="button" name="submit" id="submit" value="Register" onClick="return validateRegForm_m();"></td></tr><tr><td></td><td></td></tr><tr><td colspan="2"><a href="javascript:void(0);" onclick="loginForm1();">Already registered? Please click here to login</a></td></tr></tbody></table></form>';
}
function passwwordReset(){
	
document.getElementById('reglogin').innerHTML='<form name="frmrReset" id="frmrReset" method="post"><table width="100%" cellpadding="3" cellspacing="3" align="left"><td colspan="2" class="mandatory" id="warning" align="center"></td></tr><tr><td>Email</td><td><input type="text" value="" name="email" id="email" /><span class="mandatory">*</span></td></tr><tr><td></td><td><input type="button" name="passreset" id="passreset" value="Send" onClick="return sendPassword();"/></td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td align"left" colspan="2"><a href="javascript:void(0);" onclick="showRegForm();">Back to Registration</a></td></tr></table></form>';
}
function passwwordReset1(){
	
document.getElementById('member_register').innerHTML='<form name="frmrReset" id="frmrReset" method="post"><table width="100%" cellpadding="3" cellspacing="3" align="left"><td colspan="2" class="mandatory" id="warning_m" align="center"></td></tr><tr><td>Email</td><td><input type="text" value="" name="email" id="email" /><span class="mandatory">*</span></td></tr><tr><td></td><td><input type="button" name="passreset" id="passreset" value="Send" onClick="return sendPassword1();"/></td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td align"left" colspan="2"><a href="javascript:void(0);" onclick="showRegForm1();">Back to Registration</a></td></tr></table></form>';
}


function sendPassword(){

	action = "resetPassword";
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	alert ("Browser does not support HTTP Request")
	return
	} 
	
	var url="ajxCommon.php";
	email = document.getElementById("email").value;
	if(email==''){
		alert("Please enter your email");
	 	document.getElementById("email").focus();
	 	return false;
	}else if(echeck(document.getElementById("email").value)==false){
		document.getElementById("email").value ='';
		document.getElementById("email").focus()
		return false;
	}
	url=url+"?action="+action+"&email="+email;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	return true;
}

function sendPassword1(){

	action = "resetPassword";
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	alert ("Browser does not support HTTP Request")
	return
	} 
	
	var url="ajxCommon.php";
	email = document.getElementById("email").value;
	if(email==''){
		alert("Please enter your email");
	 	document.getElementById("email").focus();
	 	return false;
	}else if(echeck(document.getElementById("email").value)==false){
		document.getElementById("email").value ='';
		document.getElementById("email").focus()
		return false;
	}
	url=url+"?action="+action+"&email="+email;
	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=stateChanged_m;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	return true;
}

function validateloginfrm( type){
	if(document.getElementById("email").value==''){
		alert("Please enter email");
		document.getElementById("email").focus();
		return false;
	}
	if (echeck(document.getElementById("email").value)==false){
		document.getElementById("email").value ='';
		document.getElementById("email").focus()
		return false;
	}
	if(document.getElementById("password").value==''){
		alert("Please enter password");
		document.getElementById("password").focus();
		return false;
	}
		checkLoginFields(type);

	return true;
}
function checkLoginFields(type){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	alert ("Browser does not support HTTP Request")
	return
	} 
	action = "checkFields";	
	var url="ajxCommon.php";
	email = document.getElementById("email").value;
	password = document.getElementById("password").value;
	
	url=url+"?action="+action+"&email="+email+"&passwd="+password;
	url=url+"&sid="+Math.random();
	if(type=='1')
	xmlHttp.onreadystatechange=stateChanged_m;
	else
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function register(type){
//alert('gggggggg');
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	alert ("Browser does not support HTTP Request")
	return
	} 
	action = "register";	
	var url="ajxCommon.php";
	if(type!="m")
	{
	username = document.getElementById("name").value;
	password = document.getElementById("password").value;
	email = document.getElementById("email").value;
	telephone = document.getElementById("telephone").value;
	}
	else
	{
	username = document.getElementById("name_m").value;
	password = document.getElementById("password_m").value;
	email = document.getElementById("email_m").value;
	telephone = document.getElementById("telephone_m").value;
	}
	url=url+"?action="+action+"&uname="+username+"&passwd="+password+"&email="+email+"&telephone="+telephone;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}
function loadImages(id){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	alert ("Browser does not support HTTP Request")
	return
	} 
	action = "loadImages";	
	var url="ajxCommon.php";
		
	url=url+"?action="+action+"&catid="+id;
//	alert(url);
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged1;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}

function stateChanged_m() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		var result = xmlHttp.responseText;
		
		if(action=="resetPassword")
		{
		
			if(result=='success'){
				//alert(result);
			document.getElementById("member_register").innerHTML = 'Your password details have been emailed to you.<br><br><a href="javascript:void(0);" onclick="loginForm1();">Click here to login</a>';
			document.getElementById("member_processing").innerHTML = '';
			}else{
				
				passwwordReset1();
			document.getElementById("warning_m").innerHTML = result;
			document.getElementById("member_processing").innerHTML = '';
			}
			
		}else if(action=="checkFields"){
			if(result=='success'){
				window.location = "index.php?page=gallery";
				
			}else{
				loginForm1();
			document.getElementById("warning_m").innerHTML = result;
			document.getElementById("member_processing").innerHTML = '';
			}
		}else if(action=="register"){
			//alert(result);
				if(result=='success'){
					window.location =  "index.php?page=gallery";
				}else{
					showRegForm();
					document.getElementById("warning_m").innerHTML = result;
					document.getElementById("member_processing").innerHTML = '';
				}
		}else{
			document.getElementById("member_processing").innerHTML = "Loading....";
		}
	} else{
		document.getElementById("member_processing").innerHTML = "Loading....";
	}
} 


function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		var result = xmlHttp.responseText;
		if(action=="resetPassword")
		{
			if(result=='success'){
				//alert(result);
			document.getElementById("reglogin").innerHTML = 'Your password details have been emailed to you.<br><br><a href="javascript:void(0);" onclick="loginForm();">Click here to login</a>';
			document.getElementById("processing").innerHTML = '';
			}else{
				passwwordReset();
			document.getElementById("warning").innerHTML = result;
			document.getElementById("processing").innerHTML = '';
			}
			
		}else if(action=="checkFields"){
			if(result=='success'){
				window.location = "index.php?page=gallery";
				
			}else{
				loginForm();
			document.getElementById("warning").innerHTML = result;
			document.getElementById("processing").innerHTML = '';
			}
		}else if(action=="register"){
			//alert(result);
				if(result=='success'){
					window.location =  "index.php?page=gallery";
				}else{
					showRegForm();
					document.getElementById("warning").innerHTML = result;
					document.getElementById("processing").innerHTML = '';
				}
		}else{
			document.getElementById("processing").innerHTML = "Loading....";
		}
	} else{
		document.getElementById("processing").innerHTML = "Loading....";
	}
} 

function getPageinfo(page){
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	alert ("Browser does not support HTTP Request")
	return
	} 
	action = "ourfriends";	
	var url="ajxCommon.php";
		
	url=url+"?action="+action+"&pageid="+page;
//	alert(url);
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged_new;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}

function showContent1(page){
		$(".main").hide();
		$(".side").hide();	
		showContent(page);
	
}
function stateChanged1() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		var result = xmlHttp.responseText;
		if(action=="loadImages"){
			result = result.split('*');
			
					if(document.getElementById("gnav")){
						if(result[1]<=9){
						document.getElementById("gnav").style.display = 'none';
						
					}else{
						document.getElementById("gnav").style.display = 'block';
					}
				}
				if(result[0]!=''){
					//alert(result[0]);
					if(document.getElementById("gcontent"))
					{
						document.getElementById("gcontent").innerHTML = result[0];	
					}
					//document.getElementById("slides").innerHTML = result[0];	
					$('.thumbs a').lightBox();
					$('#slides').jcarousel({
					initCallback: mycarousel_initCallback,
					buttonNextHTML: null,
					buttonPrevHTML: null,
					scroll: 1,
					start: 1
					});
					//carousel.setProperty("size", 17);
				//document.getElementById("slides").style.width = "575px";
					//document.getElementByTagName("li").style.width = "575px";					
				}else{
					if(document.getElementById("gcontent"))
					{
						document.getElementById("gcontent").innerHTML = "Loading....";
					}
					//document.getElementById("slides").innerHTML = "Loading....";
				}
	}
	}else{
		if(document.getElementById("gcontent"))
		{
			document.getElementById("gcontent").innerHTML = "Loading....";
		}
		//document.getElementById("slides").innerHTML = "Loading....";
	}
	
}