// JavaScript Document
/* Hi Resolution Image Download Start Here  Razeeth */
function changePic1(srcc,desc)
	{
		document.getElementById('mainPic').src=srcc;
		document.getElementById('mainPic1').src=desc;
		//document.getElementById('blankatPic').src=blankat;
		//document.getElementById('filepath').value = srcc;
		document.getElementById('prodfilepath').value = srcc;
		document.getElementById('prodfilepath1').value = desc;
		//document.getElementById('prodfilepath').value = blankats;
		
	}
function changePic(srcc)
	{
		document.getElementById('mainPic').src=srcc;
		document.getElementById('prodfilepath').value = srcc;
		document.getElementById('prodfilepath1').value = srcc;
		//document.getElementById('prodfilepath').value = blankats;
		
	}	
	
	//function Pic(srcc,blanksrc)
//	{
//		document.getElementById('mainPic').src=srcc;
//		//document.getElementById('blankatPic').src=blankat;
//		//document.getElementById('filepath').value = srcc;
//		document.getElementById('prodfilepath').value = blanksrcc;
//		//document.getElementById('prodfilepath').value = blankat;
//		
//	}
	
	/*function blankatPic(srcc,blanksrc)
	{
		document.getElementById('mainPic').src=srcc;
		document.getElementById('blankat').src=blanksrc;
		//document.getElementById('filepath').value = srcc;
		document.getElementById('prodfilepath').value = srcc;
		
	}*/

function chkprodavail()
	{
		if(document.getElementById('prodfilepath').value=="")
			{
				alert("select any one product")
				return false;
			}
		else
			{
				return true;
			}
	}
	
	function chkprodavail1()
	{		
		if(document.getElementById('prodfilepath1').value=="")
			{
				alert("select any one product")
				return false;
			}
		else
			{
				return true;
			}
	}
function chkmodelavail()
	{
		if(document.getElementById('modelfilepath').value=="")
			{
				alert("select any one Model")
				return false;
			}
		else
			{
				return true;
			}
	}
function centerPic(srcc,desc)
{
	document.getElementById('rollPic').src=srcc;
	document.getElementById('modelfilepath').value = srcc;
	
}
/* Hi Resoltion Image Download End Here */				

function validateregisteration()
{
		var firstname = document.registeration.txtfirstname.value;
		var lastname = document.registeration.txtlastname.value;
		var email = document.registeration.txtemailid.value;
		var username = document.registeration.txtusername.value;
		var password = document.registeration.txtpassword.value;
		
		if(trim(firstname)=="")
			{
				 document.getElementById('txtfirstname').focus();
				 alert('Enter First Name')
				 return false;
			}
		if(trim(lastname)=="")
			{
				 document.getElementById('txtlastname').focus();
				 alert('Enter Last Name')
				 return false;
			}
			
		if(trim(email)=="")
			{
				document.getElementById('txtemailid').focus();
				alert('Enter Email Address')
				return false;
			}
		
		if(trim(email)!="")
			{
				if(isEmail(trim(email))=="")
					{
						document.getElementById('txtemailid').focus();
						alert('Invalid Email Address')
						return false;
					}
			}
		if(trim(username)=="")
			{
				 document.getElementById('txtusername').focus();
				 alert('Enter User Name')
				 return false;
			}
		if(trim(password)=="")
			{
				 document.getElementById('txtpassword').focus();
				 alert('Enter Password')
				 return false;
			}
		return true;
}
function validateforgotpassword()
{
 		var email = document.forgotpassword.txtemailid.value;
		if (trim(document.getElementById('txtemailid').value) == '')
	  		{
				document.getElementById('txtemailid').focus();
	   			alert('Enter the EmailID');
	   			return false;
			}
			if(trim(email)!="")
			{
				if(isEmail(trim(email))=="")
					{
						document.getElementById('txtemailid').focus();
						alert('Invalid Email ID')
						return false;
					}
			}
		
}
function hideusername()
{
		document.getElementById('Username').value='';
		return false;
}
function hidepassword()
{
		document.getElementById('Password').value='';
		return false;
}
function chk()
	{
	    var uname = document.userlogin.Username.value;
	    var pass = document.userlogin.Password.value;
		var pathname = document.userlogin.pathname.value;
		if (trim(uname) == 0)
	  		{
	   			alert('Enter the UserName');
	   			document.userlogin.Username.focus();
	   			return false;
			}
	   if (trim(pass) == 0)
	  		{
	   			alert('Enter the Password');
	   			document.userlogin.Password.focus();
	   			return false;
			}
		if (trim(uname) == "Username")
	  		{
	   			alert('Enter the UserName');
	   			document.userlogin.Username.focus();
	   			return false;
			}
	   if (trim(pass) == "Password")
	  		{
	   			alert('Enter the Password');
	   			document.userlogin.Password.focus();
	   			return false;
			}
		xmlHttp1=GetXmlHttpObject()
		if (xmlHttp1==null)
		{
		alert ("Browser does not support HTTP Request")
		return
		} 
		xmlHttp=GetXmlHttpObject()
		var url="loginajax.php?uname="+uname+"&pass="+pass+"&pathname="+pathname+"&type=login&ranid="+Math.random();
		//alert(url);
		xmlHttp.onreadystatechange=ChkResponse; 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	  // init();
	}
	function ChkResponse() 
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		 { 
             var result= xmlHttp.responseText;
			 //alert(result);
			 var combine = result.split('*');
			 //alert(combine[0]);
			 //alert(combine[1]);
			 if (combine[0]== 1)
			 	{
					self.location=combine[1];
				}
			 else if (result== 2)
			 	{
					document.getElementById('lbl_error').innerHTML="User Name or Password is Wrong";
				}
			 else
			 	{
					document.getElementById('lbl_error').innerHTML="User Name or Password is Wrong";
				}
			 
		 } 
	}  /********end of invalid */
	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 trim(str)
		{
		  var str1=str.replace(/\S/g,"|");
		  var i=str1.indexOf("|")-1;
		  var j=str1.lastIndexOf("|")+1;
		  var trimStr=str.substring(0,i).replace(/\s/g,"") + str.substring(i+1,j)
		  trimStr = trimStr + str.substring(j).replace(/\s/g,"");
		  return trimStr;
		}
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 isEmail(email)
  {
    invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";
    for (i=0; i<invalidChars.length; i++) {
        badChar = invalidChars.charAt(i);
        if (email.indexOf(badChar,0) > -1) {
            return false;
        }
    }
    lengthOfEmail = email.length;
    if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) {
        return false;
    }
    Pos = email.indexOf("@",1);
    if (email.charAt(Pos + 1) == ".") {
        return false;
    }
    while ((Pos < lengthOfEmail) && ( Pos != -1)) {
        Pos = email.indexOf(".",Pos);
        if (email.charAt(Pos + 1) == ".") {
            return false;
        }
        if (Pos != -1) {
            Pos++;
        }
    }
    atPos = email.indexOf("@",1);
    if (atPos == -1) {
        return false;
    }
    if (email.indexOf("@",atPos+1) != -1) {
        return false;
    }
    periodPos = email.indexOf(".",atPos);
    if (periodPos == -1) {
        return false;
    }
    if (periodPos+3 > email.length) {
        return false;
    }
    return true;
	}
