var xmlhttp

function HideContent(d) {
document.getElementById(d).style.display = 'none';
}
function ShowContent(d) {

document.getElementById(d).style.display = 'block';
}

function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}



function checkAlias(q)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }
//alert(q);
	if(q.length>3)
	{  //alert('hi');
		var url="ajax/aliaslookup.asp?q="+q;

		xmlhttp.onreadystatechange=stateChangedAlias;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
	else {document.getElementById('aliasStatus').innerHTML='<font face=verdana size=1 color=#ff0000><b>Needs to be more <br>then 4 characters</b></font>';}
}

function stateChangedAlias()
{ var status='';
if (xmlhttp.readyState==4)
  { //alert(xmlhttp.responseText);
	if(xmlhttp.responseText=='0'){ status='<font face=verdana size=1 color=#4CC417><b>Username Available</b></font>'; ShowContent('createButton');}
	if(xmlhttp.responseText=='1'){ status='<font face=verdana size=1 color=#990000><b>Username Unavailable</b></font>'; HideContent('createButton');}
  document.getElementById("aliasStatus").innerHTML=status;
  }
}



function checkEmail(q)
{ 
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }

	
		var url="ajax/emaillookup.asp?q="+q;

		xmlhttp.onreadystatechange=stateChangedEmail;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	
}


function stateChangedEmail()
{ var status='';
if (xmlhttp.readyState==4)
  { //alert(xmlhttp.responseText);
	if(xmlhttp.responseText=='0'){ status='';ShowContent('createButton');}
	if(xmlhttp.responseText=='1'){ status='<font face=verdana size=1 color=#990000><b>Email already exist, <a href="/passwordrecover.asp"><font color=blue>Forgot Password?</font></a></b></font>'; 
	HideContent('createButton');}
  document.getElementById("emailStatus").innerHTML=status;
  }
}


function checkdProfile(d, t)
{ 
var status='';
	if(!t) // if non select
	{ //alert(d);
		if(document.getElementById(d).value=='')
			{ 
				status='Can Not Be Blank'; 
				document.getElementById(d+'Status').innerHTML='<font face=verdana size=1 color=#ff0000><b>'+status+'</b></font>';
			}
	}
}




function checkClassified()
{

var	email=document.getElementById('email').value;
var	conemail=document.getElementById('confirmemail').value;
var	title=document.getElementById('title').value;
var	price=document.getElementById('price').value;
var	location=document.getElementById('location').value;
var	desc=document.getElementById('desc').value;

if(!email){alert("We need the EMAIL not to be blank."); return false;}

		var str=email;
		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;
		 }
		 
		 if(email != conemail){
			alert("Email Confirmation Failed. Try Again")
			document.getElementById('confirmemail').value='';
			return false;

		}
		
		
	
	if(!title){alert("We need the TITLE not to be blank."); return false;}
	if(!price){alert("We need the PRICE not to be blank."); return false;}	
	if(!location){alert("We need the CITY not to be blank."); return false;}
	if(!desc){alert("We need the AD BODY not to be blank."); return false;}	

}

function checkContact()
{
		
var	profile=document.getElementById('profile').value;	
//var	firstname=document.getElementById('firstname').value;
//var	lastname=document.getElementById('lastname').value;
var	email=document.getElementById('email').value;
var	bm=document.getElementById('birthmonth').value;
var	bd=document.getElementById('birthdate').value;
var	by=document.getElementById('birthyear').value;
var	gender=document.getElementById('gender').value;

var	newuser=document.getElementById('newuser').value;
var	newpass=document.getElementById('newpass').value;
var	conpassword=document.getElementById('confirmpassword').value;


	if(profile==0){alert("Select PROFILE TYPE.");  return false;}
//	if(!firstname){alert("We need the FIRST NAME not to be blank."); return false;}
//	if(!lastname){alert("We need the LAST NAME not to be blank."); return false;}
	if(gender==0){alert("Select GENDER."); return(false) ;}
	if(bm==0){alert("Select BIRTH MONTH."); return false;}
	if(bd==0){alert("Select BIRTH DATE."); return false;}	  
	if(by==0){alert("Select BIRTH YEAR."); return false;}
	if(!email){alert("We need the EMAIL not to be blank."); return false;}


	if(!newuser){alert("We need the USERNAME not to be blank."); return false;}	
	if(!newpass){alert("We need the PASSWORD not to be blank."); return false;}
	if(!conpassword){alert("We need the CONFIRM PASSWORD not to be blank."); return false;}
			




	



		var str=email;
		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;
		 }
		 
		 if(newpass != conpassword){
			alert("Password Confirmation Failed. Try Again")
			document.getElementById('confirmpassword').value='';
			return false;

		}
		 
}





function sendSeller()
{
		
var	name=document.getElementById('facename').value;	
var	phone=document.getElementById('facephone').value;
var	email=document.getElementById('faceemail').value;
var	message=document.getElementById('facemessage').value;


	if(!name){alert("We need the  NAME not to be blank."); return false;}
	if(!email){alert("We need the EMAIL not to be blank."); return false;}


	if(!message){alert("We need the MESSAGE not to be blank."); return false;}	
	
		var str=email;
		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;
		 }
		 

		 
		 //*************************** CONTACT *********************

xmlHttpContact=GetXmlHttpObject();

 
var url="/ajax/sellersend.asp";
url=url+"?name="+name; 
url=url+"&phone="+phone; 
url=url+"&email="+email; 
url=url+"&message="+message; 
url=url+"&ac="+ac; 

//alert(url);
  

xmlHttpContact.onreadystatechange=stateChangedContactSeller;
xmlHttpContact.open("GET",url,true);
xmlHttpContact.send(null);
} 


function stateChangedContactSeller() 
{ 
	if (xmlHttpContact.readyState==4)
		{ 
		
		alert('Your Message Was Sent To The Seller!');
		//alert(xmlHttpContact.responseText);
			//alert(arrSuppliers);
			
			document.getElementById('facemessage').value='';
			//document.getElementById('postSend').style.display="block";
		}
	
}



//*************************** END CONTACT *****************

		 
		 
		 
		 
		 
		 
		 
		 
	


function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
