//////////////////////////
//	`	BASE JAVASCRIPT FUNCTIONS
//////////////////////////
var xuuid
var xpw
function faxit(){
	pURL= xroot + "xmain/faxinfo.html";
	new Ajax.Updater('3web', pURL, { method: 'get' })
}


function sendmsg999(){
	
	var ri_name= getfield('xname');
	var x_email= getfield('x99');
	var ri_message= getfield('themsg');

	if(ri_name==''){
		setinnerhtml("regmsg99","Name is required");
		return;
	}

	if(ri_message==''){
		setinnerhtml("regmsg99","Your Message is required");
		return;
	}	

	pURL=  "../handlers/requestinfo/?" + "thename=" + ri_name + "&theemail=" + x_email + "&themessage=" + ri_message;

			setinnerhtml("regmsg99","Sending your message");
new Ajax.Updater('regmsg99', pURL, { method: 'post' });

	
}






function business(){
MM_swapImage('Image1','','images/phone2.jpg',1)
MM_swapImage('Image3','','images/prem1.jpg',1)
MM_swapImage('Image2','','images/anywhere2.jpg',1)
MM_swapImage('Image4','','images/jobseeker2.jpg',1)
MM_swapImage('Image5','','images/wholesale1.jpg',1)

pURL= xroot + "xmain/businessinfo.html";
	new Ajax.Updater('3web', pURL, { method: 'get' });
	xmaintype = "cloud";
}
function anywhere(){
MM_swapImage('Image1','','images/phone1.jpg',1)
MM_swapImage('Image3','','images/prem1.jpg',1)
MM_swapImage('Image2','','images/anywhere1.jpg',1)
MM_swapImage('Image4','','images/jobseeker2.jpg',1)
MM_swapImage('Image5','','images/wholesale1.jpg',1)
MM_swapImage('Image6','','images/callcenter1.jpg',1)
	pURL= xroot + "xmain/anywhereinfo.html";
	new Ajax.Updater('3web', pURL, { method: 'get' });
	xmaintype = "anywhere";
}

function prem(){
MM_swapImage('Image1','','images/phone1.jpg',1)
MM_swapImage('Image3','','images/prem2.jpg',1)
MM_swapImage('Image2','','images/anywhere2.jpg',1)
MM_swapImage('Image4','','images/jobseeker2.jpg',1)
MM_swapImage('Image5','','images/wholesale1.jpg',1)
MM_swapImage('Image6','','images/callcenter1.jpg',1)
	pURL= xroot + "xmain/preminfo.html";
	new Ajax.Updater('3web', pURL, { method: 'get' });
	xmaintype = "premises";
}


function jobseeker(){
MM_swapImage('Image1','','images/phone1.jpg',1)
MM_swapImage('Image3','','images/prem1.jpg',1)
MM_swapImage('Image2','','images/anywhere2.jpg',1)
MM_swapImage('Image5','','images/wholesale1.jpg',1)
MM_swapImage('Image6','','images/callcenter1.jpg',1)
	pURL= xroot + "xmain/jobseeker.html";
	new Ajax.Updater('3web', pURL, { method: 'get' });
	xmaintype = "jobseeker";
}
function prepaid(){
MM_swapImage('Image1','','images/phone1.jpg',1)
MM_swapImage('Image3','','images/prem1.jpg',1)
MM_swapImage('Image2','','images/anywhere2.jpg',1)
MM_swapImage('Image4','','images/jobseeker2.jpg',1)
MM_swapImage('Image6','','images/callcenter1.jpg',1)
pURL= xroot + "xmain/prepaid.html";
	new Ajax.Updater('3web', pURL, { method: 'get' });
	xmaintype = "wholesaleprepaid";
}

function callcenter(){
MM_swapImage('Image1','','images/phone1.jpg',1)
MM_swapImage('Image2','','images/anywhere2.jpg',1)
MM_swapImage('Image3','','images/prem1.jpg',1)
MM_swapImage('Image5','','images/wholesale1.jpg',1)
MM_swapImage('Image4','','images/jobseeker2.jpg',1)
	pURL= xroot + "xmain/callcenter.html";
	new Ajax.Updater('3web', pURL, { method: 'get' });
	xmaintype = "callcenter";
}


function requestinfo(){
	var ri_first= getfield('rifirst');
	var ri_last= getfield('rilast');
	var ri_email= getfield('riemail');
	var ri_phone= getfield('riphone');
	var ri_company= getfield('ricompany');
	if(ri_first==''){
		setinnerhtml("regmsg","First Name is required");
		return;
	}
	if(ri_last==''){
		setinnerhtml("regmsg","Last Name is required");
		return;
	}
	if(ri_email==''){
		setinnerhtml("regmsg","Email is required");
		return;
	}
	if(ri_phone==''){
		setinnerhtml("regmsg","Phone Number is required");
		return;
	}
	if(ri_company==''){
		setinnerhtml("regmsg","Company Name is required");
		return;
	}

// OK to here.. build the request
	pURL= xroot  +  "handlers/requestinfo/?" + "firstname=" + ri_first + "&lastname=" + ri_last + "&email=" + ri_email + "&phone=" + ri_phone + "&company=" + ri_company + "&inforequest=" + rfi; 

	pURL=  xroot + "sendingrequest.php";
	new Ajax.Updater('regdiv', pURL, { method: 'get' });
	showitem('popdiv');
	showitem('regdiv');

	pURL= xroot  +  "handlers/requestinfo/?" + "firstname=" + ri_first + "&lastname=" + ri_last + "&email=" + ri_email + "&phone=" + ri_phone + "&company=" + ri_company + "&inforequest=" + rfi; 

//../handlers/requestinfo/?firstname=mark&lastname=johnson&email=caprogrammer@gmail.com&phone=714-555-1212&company=voipedge
	new Ajax.Updater('regdiv', pURL, { method: 'post' });
}

function hiderequest(){
hideitem('regdiv')
setinnerhtml('regdiv','&nbsp;')
hideitem('popdiv')
}



function moreinfo(){
	pURL= xroot  + xmaintype;
	document.location.href= pURL;
}

function setlink(){
	setstatus(pURL);
}

function unsetlink(){
	setstatus('');
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function affilsignup(){ //Start Account Registration
	setinnerhtml("popname","AFFILIATE REGISTRATION");
	showitem('popdiv');
	showitem('regdiv');
	pURL= xroot + "popups/regstep1.php";;
	new Ajax.Updater('regdiv2', pURL, { method: 'get' });
}






function regstep1continue(){//Get Registration from step one and load step2page
	pURL= xroot + "popups/regstep2.php";
	new Ajax.Updater('regdiv2', pURL, { method: 'get' });
}
function regcancel(){ //Cancel Registraton
	hideitem('regdiv');	
	hideitem('popdiv');
	setinnerhtml("regdiv2","&nbsp;");
}
function logincancel(){ //Cancel Login
	hideitem('regdiv');
	hideitem('popdiv');
	setinnerhtml("regdiv2","&nbsp;");
}
function forgotpassword(){ //Set user request password

	setinnerhtml("popname","RECOVER YOUR PASSWORD");
	showitem('popdiv');
	showitem('regdiv');
	pURL= xroot + "popups/recoverpw.php";;
	new Ajax.Updater('regdiv2', pURL, { method: 'get' });
}

function doresetpw(){

}
function signin(){ //Show Login/Signin popup
	setinnerhtml("popname","ACCOUNT LOGIN");
	showitem('popdiv');
	showitem('regdiv');
	pURL=xroot + "popups/login.php";
	new Ajax.Updater('regdiv2', pURL, { method: 'get' });;
}
function dosearch(){
}


function dologout(){
	pURL=xroot + "handlers/processlogout.php";
	processxml(pURL,"handlelogout");
}

function handlelogout(){
	if (xmlhttp.readyState==4) {
		if (xmlhttp.status==200) {
			var theresponse = xmlhttp.responseText;
			var splitresponse = theresponse.split("#");
			var xresp = splitresponse[1];
//			if (xresp=='OK') {
					window.location =xroot 
					//}
}}}



function dologin(){
	
	var uid = getfield('logid');
	var upw = getfield('logpassword');
	xuuid=uid;
	xpw = upw;
	pURL=xroot + "handlers/processlogin.php?uid=" + uid + "&upw=" + upw;
	processxml(pURL,"handlelogin");
}



function handlelogin(){
	if (xmlhttp.readyState==4) {
		if (xmlhttp.status==200) {
			var theresponse = xmlhttp.responseText;
			var splitresponse = theresponse.split("#");
			var xresp = splitresponse[1];

			if (xresp=='OK') {
				document.location.href="admin/handlers/processlogin2.php?uid=" + xuuid + "&upw=" +xpw
					//location.reload(true);

			} else {
				alert(theresponse)
}}}}





function setstatus(themsg) {	window.status=themsg   }

function setcheckbox(theitem,thestatus){
	var v_cb = document.getElementById(theitem)
	if (thestatus=="Y") {
		v_cb.checked = true 
	} else {
		v_cb.checked = false 
	}
}


function clearsearchbox(){
setfield('searchbox','');
}

function setenabledstatus(theitem,thestatus){
	var v_xx = document.getElementById(theitem)
	if (thestatus=="enable") {
		v_xx.disabled=false;
	} else {
		v_xx.disabled=true;
	}

}

function getcheckboxstatus(theitem){
	var v_cb = document.getElementById(theitem)
	if (v_cb.checked==true) {
		return "Y";;
	} else {
		return "N";
	}

}

function hideitem(theitem){
	if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
		document.getElementById(theitem).style.visibility = 'hidden';
		return;
	   } else if (window.ActiveXObject) { //IE
	   }
	var ti = 'document.all.' + theitem +  '.style.visibility = "hidden"'
	eval(ti);
	return;
}

function showitem(theitem){
	if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
		document.getElementById(theitem).style.visibility = 'visible';
		return;
	   } else if (window.ActiveXObject) { //IE
	   }
	var ti = 'document.all.' + theitem +  '.style.visibility = "visible"'
	eval(ti);
	return;
}

function saymessage(targethtml,thedata){
	document.getElementById(targethtml).innerHTML = thedata;
}

function setinnerhtml(targethtml,thedata){
	document.getElementById(targethtml).innerHTML = thedata;
}
function getinnerhtml(sourcehtml){
	thevalue =document.getElementById(sourcehtml).innerHTML;
	return thevalue;
}

function getfield(thefield){
	thevalue = document.getElementById(thefield).value;
	return thevalue;
}

function setfield(thefield,thevalue){
	document.getElementById(thefield).value = thevalue;
}

function setfieldstatus(thefield,thestatus){
	if (thestatus=='enable') {
		document.getElementById(thefield).disabled = false;
		return;
	}
		document.getElementById(thefield).disabled = true;
}

function setfocus(thefield){
	var aid =document.getElementById(thefield);
	aid.focus()
}

function processxml(pURL,handler){
        if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
               xmlhttp=new XMLHttpRequest();
              if (xmlhttp.overrideMimeType) {
                     xmlhttp.overrideMimeType('text/xml');
              }      
			  var ii = "xmlhttp.onreadystatechange=" + handler 
			  eval(ii)
              xmlhttp.open("POST", pURL, true);
              xmlhttp.send(null);
       } else if (window.ActiveXObject) { //IE
              xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
              if (xmlhttp) {
					 var ii = "xmlhttp.onreadystatechange=" + handler 
					 eval(ii)
                     xmlhttp.open('POST', pURL, false);
                     xmlhttp.send();
              }
       }
}


function showimage(){
shadewindow()
//var pURL = "http://www.itracksoftware.com/sendpagebyemail.php?pageid=" + pageid
//new Ajax.Updater('emailpage', pURL, { method: 'get' });
//showitem('emailpage')
}


function shadewindow(){
	var dhp =  getPageSizeWithScroll() 
    var groundElement = document.getElementById('fadeDiv'); 
	 groundElement.style.height = dhp + 'px'; 
	 var fadeDiv = document.getElementById("fadeDiv");
	 fadeDiv.style.display = "block";
}

function shadepopdiv(){
	var dhp =  getPageSizeWithScroll() 
    var groundElement = document.getElementById('popdiv'); 
	 groundElement.style.height = dhp + 'px'; 
	 var fadeDiv = document.getElementById("popdiv");
	 fadeDiv.style.display = "block";
}

function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;

	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
			if(yWithScroll<10){
			yWithScroll = window.innerHeight
		}
	arrayPageSizeWithScroll = yWithScroll;
	return arrayPageSizeWithScroll;
}

function hideimage(){
var fadeDiv = document.getElementById("fadeDiv");
fadeDiv.style.display = "none";
}

var xmaintype='anywhere';
/////////////
//	END BASE FUNCTIONS
/////////////

