﻿// JScript File

var mousedown=0;

function showOver(obj)
{
	if (obj.disabled) {
		obj.className = 'buttonup buttondisabled';
		return;
	}
	if (mousedown==1) {
		obj.className = 'buttondown buttonmouseover';
	} else {
		obj.className = 'buttonup buttonmouseover';
	}
}
function showOut(obj)
{
	if (obj.disabled) {
		obj.className = 'buttonup buttondisabled';
		return;
	}
	if (mousedown==1) {
		obj.className = 'buttonup buttonmouseout';
	} else {
		obj.className = 'buttonup buttonmouseout';
	}
}


var lastphonenumber='';

function editphone(phone)
{

	var backspace=false;

	if (lastphonenumber.length < phone.value.length) {

		backspace=false;

	} else {

		backspace=true;

	}

	if (phone.value.length > 14) {

		phone.value = phone.value.substring(0,14);

	}


	var ch=phone.value.charAt(phone.value.length-1);

	if (!backspace && (ch < '0' || ch > '9') ) {

		phone.value = phone.value.substring(0,phone.value.length-1);

		lastphonenumber = phone.value;

		return;

	}

	var message;

	message = '<code><table>';

	message = message + '<tr><td>backspace:</td><td>' + backspace + '</td></tr>';

	message = message + '<tr><td>Last phone:</td><td>[' + lastphonenumber + '] ' + lastphonenumber.length + '</td></tr>';

	message = message + '<tr><td> cur phone:</td><td>[' + phone.value + '] ' + phone.value.length + '</td></tr>';

	message = message + '<tr><td colspan="2"><hr></td></tr>';

	if (phone.value.length==3 && !backspace) {
		phone.value = '('+phone.value+') ';

	}

	if (phone.value.length==5 && backspace) {

		phone.value = phone.value.substring(1,3);

	}

	if (phone.value.length==9 && !backspace) {

		phone.value = phone.value + '-';

	}

	if (phone.value.length==9 && backspace) {

		phone.value = phone.value.substring(0,8);

	}

	lastphonenumber = phone.value;


	message = message + '<tr><td>Last phone:</td><td>[' + lastphonenumber + '] ' + lastphonenumber.length + '</td></tr>';

	message = message + '<tr><td> cur phone:</td><td>[' + phone.value + '] ' + phone.value.length + '</td></tr>';

	message = message + '</table></code>';
	

/*	document.getElementById('status').innerHTML=message;*/
}


var nav1='';
function changeClass(object,classname)  // make highlight
{
    object.className = classname;
//    object.className = 'navfocus';
}
//function classOut(object,name)  // make highlight
//{
//    object.className = 'navout'; 
//}

function submitregistration(formid)
{
    var p1=document.getElementById("new_pwd1").value;
    var p2=document.getElementById("new_pwd2").value;

    if (p1.length < 5) {
        alert("Password must be at least 5 characters in length");
        return;
    }

    if (p1==p2) {
        document.getElementById(formid).submit();
    } else {
        alert("Passwords don't Match.");
    }   
}



var website="rkhtechnology.com"
var thankyou="Email received, thank you."
function GetXmlHttpObject()
{
  var xmlHttp=null;
  try { xmlHttp=new XMLHttpRequest(); }
  catch (e) { 
    try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
    catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
  }
  return xmlHttp;
}
function collectemail(inputid)
{ 
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="rkhapiproxy.php";
  var post="cmd=capture_email&url=";
  post=post+escape(website);
  post=post+"&email=" + document.getElementById(inputid).value;
  xmlHttp.onreadystatechange= function(){
	if (xmlHttp.readyState == 4) {
		alert(thankyou);
		document.getElementById(inputid).value='';
	}
  }
  xmlHttp.open("POST",url,true);
  //Send the proper header information along with the request
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length", post.length);
  xmlHttp.setRequestHeader("Connection", "close");
  xmlHttp.send(post);
}

function verifyemails()
{ 
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="rkhapiproxy.php";
  var post="cmd=verifyemails";
  xmlHttp.onreadystatechange= function() {
	if (xmlHttp.readyState == 4) {
	    if ((xmlHttp.responseText.charAt(0) + 1) > 1) {
//    	    document.getElementById("emailresult").innerHTML = 'refresh';
    	    location.reload(true);
	    } else {
//    	    document.getElementById("emailresult").innerHTML = 'no refresh';
	    }
	}
  }
  xmlHttp.open("POST",url,true);
  //Send the proper header information along with the request
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length", post.length);
  xmlHttp.setRequestHeader("Connection", "close");
  xmlHttp.send(post);
}



function NewContact()
{ 
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="rkhapiproxy.php";
  var post="cmd=newcontact";
  xmlHttp.open("POST",url,true);
  //Send the proper header information along with the request
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length", post.length);
  xmlHttp.setRequestHeader("Connection", "close");
  xmlHttp.send(post);
}

function setCookie(c_name,value)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+365);
document.cookie=c_name+ "=" +escape(value)+ ";expires="+exdate.toUTCString();
}

function passwordStrength(password)
{
/*
	var desc = new Array();
	desc[0] = "Very Weak"; // #ff0000
	desc[1] = "Weak";      // #ff0000  // bright red
	desc[2] = "Better";    // #cd4d4d  // dark red
	desc[3] = "Medium";    // #fffc2d  // yellow
	desc[4] = "Strong";    // #4dcd00  // dark green
	desc[5] = "Strongest"; // #00ff00  // bright green
*/
	var score   = 0;

	//if password bigger than 6 give 1 point
	if (password.length > 6) score++;

	//if password has both lower and uppercase characters give 1 point	
	if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++;

	//if password has at least one number give 1 point
	if (password.match(/\d+/)) score++;

	//if password has at least one special caracther give 1 point
	if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) )	score++;

	//if password bigger than 12 give another 1 point
	if (password.length > 12) score++;
	return score;

//	 document.getElementById("passwordDescription").innerHTML = desc[score];
//	 document.getElementById("passwordStrength").className = "strength" + score;
}

function sendmail()
{ 
  xmlPrices=GetXmlHttpObject();
  if (xmlPrices==null) {
    alert ("Your browser does not support AJAX!");
    return;
  }
  var url="/mailer/sendemail.php";
//  var post="cmd=get_current_prices";
//  xmlPrices.onreadystatechange=displayprices;
  xmlPrices.open("GET",url,true); // true=asynchronous, false=synchronous
  //Send the proper header information along with the request
//  xmlPrices.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//  xmlPrices.setRequestHeader("Content-length", post.length);
//  xmlPrices.setRequestHeader("Connection", "close");
  xmlPrices.send();
}

