// Phoenix Kiosk Inc.
// Rei  - 08-23-2007
// v2.5 - 03-03-2008


<!-- Phone Verification
var n;
var p;
var p1;
function ValidatePhone(){
p=p1.value
if(p.length==3){
	//d10=p.indexOf('(')
	pp=p;
	d4=p.indexOf('(')
	d5=p.indexOf(')')
	if(d4==-1){
		pp="("+pp;
	}
	if(d5==-1){
		pp=pp+")";
	}
	//pp="("+pp+")";
	document.form.phone.value="";
	document.form.phone.value=pp;
}
if(p.length>3){
	d1=p.indexOf('(')
	d2=p.indexOf(')')
	if (d2==-1){
		l30=p.length;
		p30=p.substring(0,4);
		//alert(p30);
		p30=p30+")"
		p31=p.substring(4,l30);
		pp=p30+p31;
		//alert(p31);
		document.form.phone.value="";
		document.form.phone.value=pp;
	}
	}
if(p.length>5){
	p11=p.substring(d1+1,d2);
	if(p11.length>3){
	p12=p11;
	l12=p12.length;
	l15=p.length
	//l12=l12-3
	p13=p11.substring(0,3);
	p14=p11.substring(3,l12);
	p15=p.substring(d2+1,l15);
	document.form.phone.value="";
	pp="("+p13+")"+p14+p15;
	document.form.phone.value=pp;
	//obj1.value="";
	//obj1.value=pp;
	}
	l16=p.length;
	p16=p.substring(d2+1,l16);
	l17=p16.length;
	if(l17>3&&p16.indexOf('-')==-1){
		p17=p.substring(d2+1,d2+4);
		p18=p.substring(d2+4,l16);
		p19=p.substring(0,d2+1);
		//alert(p19);
	pp=p19+p17+"-"+p18;
	document.form.phone.value="";
	document.form.phone.value=pp;
	//obj1.value="";
	//obj1.value=pp;
	}
}
//}
setTimeout(ValidatePhone,100)
}
function checkPhone(m){
n=m.name;
//p1=document.forms[0].elements[n]
p1=m
ValidatePhone()
}
function testphone(obj1){
p=obj1.value
//alert(p)
p=p.replace("(","")
p=p.replace(")","")
p=p.replace("-","")
p=p.replace("-","")
//alert(isNaN(p))
if (isNaN(p)==true){
alert("Check phone");
return false;
}
}

<!-- End Phone Verification



/**
 * DHTML email validation  
 */

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 ValidateForm(){
	var emailID=document.frmSample.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

/* END Script */

function assignCookieField(cookie,field)
{
 var ls___ = getCookieInfo(cookie) ;
 if (ls___ != false)
 { 
  document.form.lead_source.value = ls___ ;

 }
}

function assignTrack(cookie,field)
{
 var track___ = getCookieInfo(cookie) ;
 if (track___ != false)
 {
  var hist       = track___.split("^") ;
  var assignHist = "" ;

  for(i = 1; i <= (hist.length-1); i++)
  { 
   if (assignHist != "" || i == 1)
   { 
    assignHist = assignHist + i + "=>" + hist[i] + "\n" ;
   }
  }
  document.form.WebHistory__c.value = assignHist ;
 }
}

function setCookie(name,value)
{
 var path       = "/"           ;
 var expires    = 100000 * 60   ;
 var today      = new Date()    ;
 var domain     = "www.phoenixkiosk.com" ;
 var secure     = "" ;
// set time in milliseconds
 today.setTime( today.getTime());
 var expires_date = new Date( today.getTime() + (expires) );
 document.cookie =  name + "=" + value + ";expires=" + expires_date.toGMTString() + "; path=/" ;

}

function track___updateCookie(name)
{
 name           = "track___"       ;
 var todayGMT   = new Date()    ;
 var today      = (todayGMT.getMonth()+1) + "/" + todayGMT.getDate() + "/" + todayGMT.getFullYear() + " - " + todayGMT.getHours() + ":" + todayGMT.getMinutes() ;
 var addValue   = window.location;
 var cookieValue= getCookieInfo(name) ;
 addValue       = today + "= " + addValue ;

 if (cookieValue == false)
 {
  setCookie(name,"^"+addValue) ;
 }
 else
 {
  addValue      = cookieValue + "^" + addValue ;
  document.cookie =  name + "=" + addValue + "; path=/" ;
 }


}

function getCookieInfo(name)
{
 var start = document.cookie.indexOf( name + "=" );
 var len = start + name.length + 1;
 // if cookie doesn't exist
 if ( start == -1 )
 {
  return false ;
 }
 var end = document.cookie.indexOf( ";", len );
 if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}

function setLeadSource(name)
{
var urlString    = window.location.href ; 
var params       = urlString.split("?") ;
var allFields    = "" 			;

if (params[1] != undefined)
{
 allFields      = params[1].split("&") ;
}


var field	 = "" ;
var fieldName    = "" ; 
var fieldValue   = "" ;
var value	 = "" ;
var kwds	 = "" ;

 for (var i = 0; i <= allFields.length-1 ; i++)
 {
  field 	= allFields[i].split("=") ;  
  fieldName 	= field[0] ; 
  fieldValue	= field[1] ;   
  if (fieldName == "ls___")
  {
   value = fieldValue ; 
  }
  else if(fieldName == "_kk")
  {
   value = "Google"   ;
   kwds  = fieldValue ; 
  }
  else if(fieldName == "OVRAW")
  {
   value = "Yahoo"    ; 
   kwds  = fieldValue ; 
  }
  else if(fieldName == "_networld")
  {
  value = "Networld Alliance" ;
  kwds = fieldValue ;
  }
 }

 // temporarily
 if (value == "" && allFields[0] == "yahoo")
 {
  value = "Yahoo" ;
 }
 else if(value == "" && (allFields[0] == "business" || allFields[0] == "business.com"))
 {
  value = "business" ;  
 }
 

 // google format
 // http://dev/index.html?_kk=kiosk&_kt=23ff6828-1c45-492f-b42b-09319919b9bc&gclid=CLKSrd6XrY4CFQExYAodr1SCag
 // yahoo format
 // http://dev/index.html?OVRAW=kiosk%20digital%20signage&OVKEY=digital%20signage&OVMTC=advanced&OVADID=8090397512&OVKWID=98924743012
 // others
 // http://dev/index.html?ls=<string>
 

// var value    = window.location.search.substr(1);

 if (value != "")
 {
  setCookie(name,value);
 }
 
}



function checkProductField() {

// var interested1 = '' ;
// var interested2 = '' ;
// var interested3 = '' ;
 //var interested4 = '' ;

// if (document.form.interested1.checked){interested1 = document.form.interested1.value;}
// if (document.form.interested2.checked){interested2 = document.form.interested2.value;}
// if (document.form.interested3.checked){interested3 = document.form.interested3.value;}
// if (document.form.interested4.checked){interested4 = document.form.interested4.value;}

// document.forms[1].elements[13].value = interested1 + ',   ' + interested2 + ',    ' + interested3 + ',   ' + interested4 ;
}
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

/*
function checkOther() 
{
    var selectInduestry = document.getElementById("industry");
    var selectOther = document.getElementById("other");

    if(selectInduestry.value == "Other")
    {
        selectOther.style.display = "block";
    } else {
        selectOther.style.display = "none"
    }
}
*/
