// JavaScript Document

function $(id) { return document.getElementById(id); }
var hg=530;
function showreg(){
	$("cont-wrap").style.top="0px";	
	var col=1;
	var x;
	var y;
	$("register-btn").onclick=function(){
		clearTimeout(x);
		clearTimeout(y);
		if(col==1){
			col=2;			
			easeout(0,hg);
			document.register.username.focus();
		}else if(col==2){
			col=1;
			easein(hg,0);			
		}
		
		
	}
	
}

function easein(h,i){		
		j=h+"px";
		k=Math.floor((i-h)/5);
		h+=k;
		$("cont-wrap").style.top=j;
		if(h!=0){
			x=setTimeout("easeout("+h+","+i+")",1);
		}			
}

function easeout(h,i){
		j=h+"px";
		k=Math.floor((i-h)/5);
		h+=k;
		$("cont-wrap").style.top=j;
		if(h!=hg-4){
			y=setTimeout("easein("+h+","+i+")",1);
		}	
}


// REGISTRATION FORM VALIDATION
function checkForm(){
	
	var form=window.document.register;
	var val;
	$("submitBtn").onclick=function(){
		if(form.username.value==null || form.username.value==""){
			form.username.focus();
			alertUser("Please enter a Username");
			val=false;
		}else if(form.email.value==null || form.email.value==""){
			form.email.focus();
			alertUser("Please enter a valid email address");
			val=false;

		}else if(form.passreg.value==null || form.passreg.value=="" || form.passrega.value==null || form.passrega.value==""){
			form.passreg.value="";
			form.passrega.value="";
			form.passreg.focus();
			alertUser("Please enter a Password");
			val=false;

		}else if(form.passreg.value!=form.passrega.value){
			form.passreg.value="";
			form.passrega.value="";
			form.passreg.focus();
			alertUser("Your Passwords does not match. Please enter again");
			val=false;

		}else if(form.fname.value==null || form.fname.value==""){
			form.fname.focus();
			alertUser("Please enter your First name");
			val=false;

		}else if(form.lname.value==null || form.lname.value==""){
			form.lname.focus();
			alertUser("Please enter your Last name");
			val=false;

		}else if(form.country.selectedIndex==0){
			form.country.focus();
			alertUser("Please enter the Country you reside");
			val=false;
			
		}else if(form.timezone.selectedIndex==0){
			form.timezone.focus();
			alertUser("Please enter your Time Zone");
			val=false;
			
		}else if(form.zip.value==null || form.zip.value==""){
			form.zip.focus();
			alertUser("Please enter the zip code of your country");
			val=false;
		}else if(form.profession.selectedIndex==0){
			form.profession.focus();
			alertUser("Please enter your Profession");
			val=false;
		}else if(form.industry.selectedIndex==0){
			form.industry.focus();
			alertUser("Please enter the Industry");
			val=false;
		}else if(!form.terms.checked){
			form.terms.focus();
			alertUser("You have to agree to our Terms and Conditions to continue registration");
			val=false;
		}else{
			val=true;
			}
		if(val==true){
			$("regform-feedback").style.visibility="hidden";
			}
	}
}
function alertUser(msg){
	clearTimeout(alertUserTimeout())
	$("regform-feedback").style.visibility="visible";
	$("regform-feedback").innerHTML=msg;
	setTimeout("alertUserTimeout()",10000);
}

function alertUserTimeout(){
	$("regform-feedback").style.visibility="hidden";	
}


//Forgot Pass

function forgotPass(){	
	str='<div class="pop-inner">'
			+'<h3>Forgot Password</h3>'
			+'<div class="close" title="Close Forgot Password" onclick="javascript:overlayAlertRem();"></div>'
			+'<form name="fpform" id="fpform" action="./forgotPassword" method="post">'
				+'<div class="pop-inner-cont">'
					+'<label>Please enter your email Id</label>'
					+'<input type="text" id="uid" name="email" />'
					+'<input type="submit" value="Email my Password" id="fp-btn" name="fp-btn" />'
					+'<p class="hint">Your password will be sent to the email id you had provided at the time of Registration</p>'
				+'</div>'
			+'</form>'
		+'</div>';
	displayAlert("forgotpass-div","wrapper","400",str);
	
		document.fpform.uid.focus();
	
}

function displayterms(){
	
	str='<div class="pop-inner"><h3>Terms and Conditions</h3> <div class="close" title="Close Terms and Conditions" onclick="overlayAlertRem()"></div> <div class="pop-inner-cont fixed"> <p>Welcome! By using vizBs search engine or other vizB services ("vizB Services"), you agree to be bound by the following terms and conditions (the "Terms of Service"). As used in this agreement, "vizB Services" does not include the Adwords or Adsense programs.</p> <h4>Personal Use Only </h4> <p>The vizB Services are made available for your personal, non-commercial use only. You may not use the vizB Services to sell a product or service, or to increase traffic to your Web site for commercial reasons, such as advertising sales. You may not take the results from a vizB search and reformat and display them, or mirror the vizB home page or results pages on your Web site. You may not "meta-search" vizB. If you want to make commercial use of the vizB Services, you must enter into an agreement with vizB to do so in advance. Please contact us for more information.  If you are interested in adding a vizB search box to your web site or your companys web site, we encourage you to do so. </p> <h4>No Automated Querying</h4> <p>You may not send automated queries of any sort to vizBs system without express permission in advance from vizB.</p> <p>Note that "sending automated queries" includes, among other things:</p> </div> </div>';
	
	displayAlert("termspop","wrapper",null,str);
	
}

function displayprivacy(){
	
	str='<div class="pop-inner"><h3>Privacy Policy</h3><div class="close" title="Close Privacy Policy" onclick="overlayAlertRem()"></div><div class="pop-inner-cont fixed"><p>The guiding principle of our privacy policy comes from the ethic of reciprocity. <a href="http://en.wikipedia.org/wiki/Ethic_of_reciprocity" rel="external">http://en.wikipedia.org/wiki/Ethic_of_reciprocity</a></p> <p>We don’t like to have our privacy violated nor do we want anyone else’s privacy to be violated. In this day and age where information is so readily available it is up to us as citizens of the new information age to hold dear and protect the one thing that is uniquely us: our personal space.  At times we give that trust for others to hold, the trust of guarding the information that could violate our personal space.  We as citizens of this new information rich world have to hold that personal information as if it was our own, treat it as if our own personal space is at stake.  This is our guiding principle. </p>  <p>We hope that every one in the world will live by this guiding principle.  Those that do not should be guided to see the way to become part of the world that cares about caring for others as in the end it is themselves they are caring for.</p> <p><em>-The vizB team</em></p> <h4>Here are some details:</h4> <p>If you are over the age of 13, vizB will collect information related to you as an individual such as your name and contact information and other personal information that should not be publically available.</p> <p>If you are under the age of 13, we will not ask you for your information.</p> <p>We will not share your individual information with anyone. Period.  We will however take your general usage information based on your demographic information and compile into a generic study for use such as marketing within vizB.</p> <p>Also, the use of cookies may be employed and if so, it will only be employed for the use of collecting generic information in regards to how you are using vizB and then generically catalogued as demographic information to better serve us.  Will not under any circumstances use any cookies to track your behavior outside of vizB.</p></div></div>';
	
	displayAlert("termspop","wrapper",null,str);
	
}

function displayAlert(cDiv,wrap,cWidth,msg){
	
	pagesize();
	
	var e = document.createElement("div");
	var f = document.createElement("div");
	
	e.id="divoverlay";
	f.id=cDiv;
	
	//$(wrap).appendChild(e);
	$(wrap).appendChild(f);
	
	//$("divoverlay").style.display="block";
//	$("divoverlay").style.height=arrayPageSize[3];
	
	if(cWidth!=null){
		pW=(arrayPageSize[0]/2)-(cWidth/2);
		pH=(arrayPageSize[3]/2.5);
		$(cDiv).style.left=pW+"px";
		$(cDiv).style.top=pH+"px";
	}	
	$(cDiv).style.display="block";	
	$(cDiv).innerHTML = msg;
	}
	
function overlayAlertRem(){
	//ol = $("divoverlay");
	//ol.parentNode.removeChild(ol);
	if($("forgotpass-div")){
		fp = $("forgotpass-div");
		fp.parentNode.removeChild(fp);
	}else if($("termspop")){
		tp = $("termspop");
		tp.parentNode.removeChild(tp);
		}
}

//HEIGHT WIDTH OF THE PAGE
function pagesize(){
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	}
function showDiv(divId,styleClass,innerHtml){
	if(divId){
		if(styleClass){
			divObj = document.getElementById(divId);
			divObj.style.display = "block";
			divObj.className = styleClass;
		}else{
			divObj = document.getElementById(divId);
			divObj.style.display = "block";
		}
		if(innerHtml){
			divObj = document.getElementById(divId);
			divObj.innerHTML = innerHtml;
		}
	}
}
function openBrowserDialog(link){
		window.open(link,'uploadImageWindow','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=800px,height=530px,left = 80,top = 80');
}