function subPackage(packId,subpackId,requestUrl){
	var URLADD = document.location.href;
	
	if(URLADD.match(/packages/g)=="packages"){
		var splitUrl = URLADD.split("packages");
		var url = splitUrl[0]+"packages/name/"+requestUrl;
	}
	
	//alert(packId+' : '+subpackId+' : '+url);
	//var urlvalue = document.location.href;
	//var splitUrl = urlvalue.split("=");

	document.controll["packageId"].value=packId;
	document.controll["subPackageId"].value=subpackId;
	document.controll.action = url;
	
	document.controll.submit();
	
}


function subPackage2(packId,subpackId,requestUrl){
	var URLADD = document.location.href;
	
	if(URLADD.match(/machines/g)=="machines"){
		var splitUrl = URLADD.split("machines");
		var url = splitUrl[0]+"packages/name/"+requestUrl;
	}

	document.controll["packageId"].value=packId;
	document.controll["subPackageId"].value=subpackId;
	document.controll.action = url;
	//alert(url+'===='+packId+'==='+subpackId);
	document.controll.submit();
	
}





//==================validate login in the header portion===========
function validatelogin(frmObj){
	
	
	if((frmObj.loginPass.value.search(/\S/)==-1) && (frmObj.loginUser.value.search(/\S/)==-1)){
		
		alert("For Registered Users only.\nPlease give userid and password to login. ");
		return false;
		
	}
	
	if(frmObj.loginPass.value.search(/\S/)==-1){
		
		alert("Please give your password.");
		return false;
		
	}
	
	if(frmObj.loginUser.value.search(/\S/)==-1){
		
		alert("Please give your userid.");
   		return false;
		
   }
	frmObj.submit();
	//return true;  
}
//==================validate login in the header portion===========





//////// To fix the flag value for forgot password ///////
/*function chkfrm()
  {
  document.frm_myaccount.flag.value="forgotpasswd";
  document.frm_myaccount.submit();
  return;
}*/

////////////  Validation for forgot password ///////////
function validatefgtform()
{
  if(document.frm_forgotpassword.forget_userid.value.search(/\S/)==-1)
    {alert("Please enter userid.");
     document.frm_forgotpassword.forget_userid.focus();
     return false;}
  if(document.frm_forgotpassword.forget_zip.value.search(/\S/)==-1 || !ValidateNo(document.frm_forgotpassword.forget_zip.value,"1234567890"))
    {alert("Please enter valid zipcode.");
    document.frm_forgotpassword.forget_zip.focus();
    return false;}
	if(document.frm_forgotpassword.forget_email.value.search(/\S/)==-1)
    {alert("Please enter your email.");
    document.frm_forgotpassword.forget_email.focus();
    return false;}
	if(!ValidateForm(document.frm_forgotpassword.forget_email))
    { return false;
    }
	document.frm_forgotpassword.flag.value="passwdchecked";
	document.frm_forgotpassword.submit();
	return true;
}
	
	
//   NEW REGISTRATION (form validation)
<!--
function validateregform()
{
  if(document.frm_newregister.new_userid.value.search(/\S/)==-1)
    {alert("Please enter userid.");
     document.frm_newregister.new_userid.focus();
     return false;}
  if(document.frm_newregister.new_passwd.value.search(/\S/)==-1)
    {alert("Please enter password.");
    document.frm_newregister.new_passwd.focus();
    return false;}
  if(document.frm_newregister.confirm_passwd.value.search(/\S/)==-1)
    {alert("Please enter confirm password.");
    document.frm_newregister.confirm_passwd.focus();
    return false;}	
	if(document.frm_newregister.new_passwd.value.length<6)
    {alert("Please give atleast six characters for your password.");
    document.frm_newregister.new_passwd.focus();
    return false;}
  if(document.frm_newregister.new_fname.value.search(/\S/)==-1)
    {alert("Please enter first name.");
    document.frm_newregister.new_fname.focus();
    return false;}
  if(document.frm_newregister.new_lname.value.search(/\S/)==-1)
    {alert("Please enter last name.");
    document.frm_newregister.new_lname.focus();
    return false;}
  if(document.frm_newregister.new_address.value.search(/\S/)==-1)
    {alert("Please enter address.");
    document.frm_newregister.new_address.focus();
    return false;}
  if($('new_country').value=='')
    {alert("Please select country.");
    document.frm_newregister.new_country.focus();
    return false;}
  if(document.frm_newregister.new_state.value.search(/\S/)==-1)
    {alert("Please enter state.");
    document.frm_newregister.new_state.focus();
    return false;}
  if(document.frm_newregister.new_city.value.search(/\S/)==-1)
    {alert("Please enter city.");
    document.frm_newregister.new_city.focus();
    return false;}
  if(document.frm_newregister.new_zip.value.search(/\S/)==-1 || !ValidateNo(document.frm_newregister.new_zip.value,"1234567890"))
    {alert("Please enter valid zipcode.");
	document.frm_newregister.new_zip.value="";
    document.frm_newregister.new_zip.focus();
    return false;}
  if(document.frm_newregister.new_email.value.search(/\S/)==-1)
    {alert("Please enter you email address.");
    document.frm_newregister.new_email.focus();
    return false;}
  if(document.frm_newregister.confirm_passwd.value!=document.frm_newregister.new_passwd.value)
    {alert("Please correct the confirm password.");
    document.frm_newregister.confirm_passwd.focus();
    return false;}	
	
  if(!ValidateForm(document.frm_newregister.new_email))
    { return false;
    }
  if((document.frm_newregister.home_phone.value.search(/\S/)==-1) || !phoneformat(document.frm_newregister.home_phone))
    {alert("Please enter you home phone numbers.");
    document.frm_newregister.home_phone.focus();
    return false;}
  if((document.frm_newregister.work_phone.value.search(/\S/)==-1) || !phoneformat(document.frm_newregister.work_phone))
    {alert("Please enter you work phone number.");
    document.frm_newregister.work_phone.focus();
    return false;}
  document.frm_newregister.flag.value="register"; 
   /*document.frm_newregister.new_city_final.value = $('new_city_add').value;*/
  document.frm_newregister.submit();
  return true;       
}

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 phoneformat(obj1){
	p=obj1.value
	p=p.replace("","")
	p=p.replace("-","")
	p=p.replace("-","")
	p=p.replace("-","");
	if (p.length>0 && p.length<10){
		return false;
	}
	//alert(isNaN(p))
	if (isNaN(p)==true){
		return false;
	}
	return true;
}

function ValidateForm(mail){
	var emailID=mail
	
	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
 }
 
 function ValidateNo(NumStr, String)
    {
    for(var Idx=0; Idx<NumStr.length; Idx++)
    {
        var Char = NumStr.charAt(Idx);
        var Match = false;

        for(var Idx1=0; Idx1<String.length; Idx1++)
         {
            if(Char == String.charAt (Idx1))
                Match = true;
         }

        if (!Match)
          return false;
    }
    return true;
 } 
 
 
 //======================handle user account operation=======================
 function handleAcc(action){
	 	alert(action);
		document.accOperate.flag.value = action;
		document.accOperate.action = "myaccount";//alert(document.accOperate.action);
		document.accOperate.submit();
}
 
 
 
 function validatechngPass(){
	if(document.frm_changePass.oldpass.value.search(/\S/)==-1){
		alert("Please enter old password.");
		document.frm_changePass.oldpass.value = "";
    	document.frm_changePass.oldpass.focus();
    	return false;
	} 
	if(document.frm_changePass.newpass.value.search(/\S/)==-1){
		alert("Please enter new password.");
		document.frm_changePass.newpass.value = "";
    	document.frm_changePass.newpass.focus();
    	return false;
	}
	if(document.frm_changePass.cnfpass.value.search(/\S/)==-1){
		alert("Please enter confirm password.");
		document.frm_changePass.cnfpass.value = "";
    	document.frm_changePass.cnfpass.focus();
    	return false;
	}
	if(document.frm_changePass.newpass.value.length<6){
		alert("Password must be more than six(6) charecters.");
    	document.frm_changePass.newpass.value = "";
		document.frm_changePass.newpass.focus();
    	return false;
	}
	if(document.frm_changePass.newpass.value!=document.frm_changePass.cnfpass.value){
		alert("Confirm password do not match.");
    	return false;
	}
	document.frm_changePass.submit();
}


function validateAccDetail(){
	
  if(document.frm_chngAcc.new_fname.value.search(/\S/)==-1)
    {alert("Please enter first name.");
    document.frm_chngAcc.new_fname.focus();
    return false;}
  if(document.frm_chngAcc.new_lname.value.search(/\S/)==-1)
    {alert("Please enter last name.");
    document.frm_chngAcc.new_lname.focus();
    return false;}
  if(document.frm_chngAcc.new_address.value.search(/\S/)==-1)
    {alert("Please enter address.");
    document.frm_chngAcc.new_address.focus();
    return false;}
  if($('new_country').value=="")
    {alert("Please select country.");
    document.frm_chngAcc.new_country.focus();
    return false;}
  if(document.frm_chngAcc.new_state.value.search(/\S/)==-1)
    {alert("Please enter state.");
    document.frm_chngAcc.new_state.focus();
    return false;}
  if(document.frm_chngAcc.new_city.value.search(/\S/)==-1)
    {alert("Please enter city.");
    document.frm_chngAcc.new_city.focus();
    return false;}
  if(document.frm_chngAcc.new_zip.value.search(/\S/)==-1 || !ValidateNo(document.frm_chngAcc.new_zip.value,"1234567890"))
    {alert("Please enter valid zipcode.");
	document.frm_chngAcc.new_zip.value="";
    document.frm_chngAcc.new_zip.focus();
    return false;}
  /*if(document.frm_chngAcc.new_email.value.search(/\S/)==-1)
    {alert("Please enter you email address.");
    document.frm_chngAcc.new_email.focus();
    return false;}
  if(!ValidateForm(document.frm_chngAcc.new_email))
    { return false;
    }
  document.frm_chngAcc.new_city_final.value = $('new_city_edit').value;*/
  document.frm_chngAcc.submit();
  return true;}

/*function validate()
{
 if(document.getElementById('passwd').value.search(/\S/)==-1 && document.getElementById('userid').value.search(/\S/)==-1)
 {alert("For Registered Users only.\nIf you want to register please click on my account. ");
   return false;}
if(document.getElementById('passwd').value.search(/\S/)==-1)
 {alert(" Please give your password.");
   return false;}
 if(document.getElementById('userid').value.search(/\S/)==-1)
 {alert(" Please give your userid.");
   return false;}
  document.headerfrm.submit(); 
  return true;

}*/

//////// To fix the flag value for forgot password in the header///////
/*function frmForgot(){
	document.forgotPass.flag.value="forgotpass";
	document.forgotPass.submit();
  	return;
}*/


//============handle machine id on click machine name=======
function showMachine(machName,machId){
	
	document.machinesCtrl.machineId.value = machId;
	document.machinesCtrl.machineName.value = machName;
	
	var urlvalue = document.location.href;
	//var splitUrl = urlvalue.split("=");
	
	//document.machinesCtrl.action = splitUrl[0]+'=machines.'+machName;
	document.machinesCtrl.submit();
} 

/*function customize(pId){
	document.modifycart.custPackId.value = pId;
	document.modifycart.submit();
}*/

//=============need to open popup for customize packages==============
function customPackage(width,height,cId,pId){
		var ah=screen.availHeight-30;
		var aw=screen.availWidth-10;
		var xc=(aw-width)/2;
		var yc=(ah-height)/2;
        
		var base_url=document.location.href.replace("shopping-cart","pages/customize-package.php");
		var url = base_url+"?cId="+cId+"&pId="+pId;
		var w_options="width="+width+",height="+height+",left="+xc+",top="+yc+",location=no,menubar=no,resizable=1,"+
		              "scrollbars=yes,status=no,toolbar=no,dependent=yes,directories=no,titlebar=no";	
		var win=window.open(url,"win",w_options);

}
//=============need to open popup for customize packages==============


//================check salse access level ================================
function checkSalesAccess(userLevel){
	var ULevel =  userLevel;

	if(typeof(ULevel)=="undefined"){
		alert('Sorry !! You need to be logged in first');
		return false;
	}
	else{
		if(ULevel==5){
			return true;	
		}
		else{
			alert('Opps!! Only sales persons have access on this page.');
			return false;
		}
	}
}

//================check salse access level ================================


//================check service access level ================================
function checkServiceAccess(userLevel){
	var ULevel =  userLevel;

	if(typeof(ULevel)=="undefined"){
		alert('Sorry !! You need to be logged in first');
		return false;
	}
	else{
		if(ULevel==6){
			return true;	
		}
		else{
			alert('Opps!! Only service providers have access on this page.');
			return false;
		}
	}
}

//================check service access level ================================


//=========need to see details of the particular order=====================
function detailOrderView(orderId){
	document.frm_orderDet.subFlag.value = "viewOrderDetail";	
	document.frm_orderDet.odrID.value = orderId;
	document.frm_orderDet.submit();
}
//=========need to see details of the particular order=====================


//================check user access level ================================
function checkUserLogin(userSession, param){
	if(userSession==''){
		alert('Sorry !! You need to be logged in first');
		return false;
	}
	else{
		if(param=="forum"){
			openForum(900,550);
		}
		else{
			return true;
		}
	}
}
//================check user access level ================================

//=============need to open popup for customize packages==============
function openForum(width,height){
		var ah=screen.availHeight-30;
		var aw=screen.availWidth-10;
		var xc=(aw-width)/2;
		var yc=(ah-height)/2;
        
		var w_options="width="+width+",height="+height+",left="+xc+",top="+yc+",location=no,menubar=no,resizable=0,"+
		              "scrollbars=yes,status=no,toolbar=no,dependent=yes,directories=no,titlebar=no";	
		var win=window.open("forum/index.php","win",w_options);

}
//=============need to open popup for customize packages==============



//=============need to open popup for customize packages==============
function printorder(width,height,ordId,pId){
		var ah=screen.availHeight-30;
		var aw=screen.availWidth-10;
		var xc=(aw-width)/2;
		var yc=(ah-height)/2;
		//============
		var custom_valUMPC=document.frm.custom_valUMPC.value;
		var colors=document.frm.colors.value;
		var FunctionKeysRadio=document.frm.FunctionKeysRadio.value;
		var NumberBarRadio=document.frm.NumberBarRadio.value;
		var KeysRadio=document.frm.KeysRadio.value;
		var WideLeftRadio=document.frm.WideLeftRadio.value;
		var WideRightRadio=document.frm.WideRightRadio.value;
		var WideKeysRadio=document.frm.WideKeysRadio.value;
		var chkProtection=document.frm.chkProtection.value;
		var Protection=document.frm.Protection.value;
		var custom_val=document.frm.custom_val.value;
		var isCheckedCustomButton=document.frm.isCheckedCustomButton.value;
		var paintValue=document.frm.paintValue.value;
		var paintDescription=document.frm.paintDescription.value;
		
		var pars ="proOrderID="+ordId;
		    pars = pars +"&pId="+pId;
			pars = pars +"&colors="+colors;
		    pars = pars +"&FunctionKeysRadio="+FunctionKeysRadio;
		    pars = pars +"&NumberBarRadio="+NumberBarRadio;
			pars = pars +"&KeysRadio="+KeysRadio;
			pars = pars +"&WideLeftRadio="+WideLeftRadio;
			pars = pars +"&WideRightRadio="+WideRightRadio;
			pars = pars +"&WideKeysRadio="+WideKeysRadio;
			pars = pars +"&chkProtection="+chkProtection;
			pars = pars +"&Protection="+Protection;
			pars = pars +"&custom_val="+custom_val;
			pars = pars +"&isCheckedCustomButton="+isCheckedCustomButton;
			pars = pars +"&paintValue="+paintValue;
			pars = pars +"&paintDescription="+paintDescription;
			pars = pars +"&custom_valUMPC="+custom_valUMPC;
			
        //============
		var base_url=document.location.href.replace("shopping-cart","pages/printOrder.php");
		var url = base_url+"?"+pars;
		var w_options="width="+width+",height="+height+",left="+xc+",top="+yc+",location=no,menubar=no,resizable=1,"+
		              "scrollbars=yes,status=no,toolbar=no,dependent=yes,directories=no,titlebar=no";	
		var win=window.open(url,"win",w_options);

}
//=============need to open popup for customize packages==============

//==========valid tradein/upgrde field in shopping cart area===========
	validTradeOnfocus = function(el){
			el.value = "";
	}
	
	validTradeOnBlur = function(el){
		
		if(el.value.toString().indexOf("$")!=-1){
		  el.value=el.value.toString().substr(1,el.value.toString().length);	
		}
		
		var total = 0;
		var deposite = 0;
		var tradeval = 0;
		
		var discountArr = el.form['Discount'].value.split("$");
		var discount = parseFloat(discountArr[1]);
		
		var taxArr = el.form['Tax'].value.split("$");
		var tax = parseFloat(taxArr[1]);
		
		var shippingHandleArr = el.form['ShippingCost'].value.split("$");
		var shippingHandle = parseFloat(shippingHandleArr[1]);
		
		var subtotalArr = el.form['SubTotal'].value.split("$");
		var subtotal = parseFloat(subtotalArr[1]);

		var amount1 = (subtotal+tax+shippingHandle);
		var amount2 = 0;
//alert("Discount: "+discount+"   Tax: "+tax+"   ShippingHandle: "+shippingHandle+"  SubTotal: "+subtotal);
//alert("Amount Total[1]: "+amount1);
	
		if(el.name=="TradeOrUpgrade"){
			tradeval = parseFloat(el.value);
		}
		if(el.name=="Depositval"){
			deposite = parseFloat(el.value);
		}
		//alert("Trade Value: "+tradeval+" Deposite: "+deposite);
		//var numstr=1;
		//var num=numstr.toFixed(2);
		//alert(numstr.toFixed(2))
		
		
		//alert(el.value);
		if(isNaN(el.value) || (el.value=="")){
  			alert("Amount Required For This Field!");
			if(el.name=="TradeOrUpgrade"){
				deposite = el.form['Depositval'].value.split("$");
				//alert(deposite+"+"+parseFloat(discount[1])+"++"+parseFloat(tradeval));
				amount2 = (discount+parseFloat(deposite[1]));
				el.form['Amount'].value = "$"+(amount1-amount2);//+".00"
				//alert("Amount2: "+amount2+"  Form Amount: "+el.form['Amount'].value);
			}
			
			if(el.name=="Depositval"){
				tradeval = el.form['TradeOrUpgrade'].value.split("$");
				amount2 = (discount+parseFloat(tradeval[1]));
				el.form['Amount'].value = "$"+(amount1-amount2);//+".00"
			}
			
			el.value = "$0.00";
			//alert(amount1+" :==: "+amount2);
			//alert("hh"+el.form['Amount'].value);
			//el.form['Amount'].value = "$"+el.form['hideOriginalAmount'].value;
		}
		else{
			
			if(el.name=="TradeOrUpgrade"){
				deposite = el.form['Depositval'].value.split("$");
				amount2 = (parseFloat(discount)+parseFloat(tradeval)+parseFloat(deposite[1]));
				total = (amount1-amount2);
				
			}
			if(el.name=="Depositval"){
				tradeval = el.form['TradeOrUpgrade'].value.split("$");
				amount2 = (parseFloat(discount)+parseFloat(tradeval[1])+parseFloat(deposite));
				total = (amount1-amount2);
				//alert("Total: "+total+" Trade: "+tradeval[1]+" Discount: "+discount);
			}
			
			if(total<0){
				alert("Trade in / Upgrade amount can not be more than total amount.");
				
				el.form['TradeOrUpgrade'].value = "$0.00";
				el.form['Depositval'].value = "$0.00";
				amount2 = (discount);
				total = amount1-amount2;
				el.form['Amount'].value = "$"+total.toFixed(2);
			}
			else{
				
				if(el.name=="TradeOrUpgrade"){
					el.form['TradeOrUpgrade'].value = "$"+tradeval.toFixed(2);
					el.form['Depositval'].value = "$"+parseFloat(deposite[1]).toFixed(2);
				}
				if(el.name=="Depositval"){
					el.form['TradeOrUpgrade'].value = "$"+parseFloat(tradeval[1]).toFixed(2);
					el.form['Depositval'].value = "$"+deposite.toFixed(2);
				}
				
				el.form['Amount'].value = "$"+total.toFixed(2);
				
				
				//alert(total);
				
				/*if(total<=2000){
					delete_option("payMode","FINANCE");
				}
				else{
					add_option("payMode","FINANCE","Financing");
				}*/
			}//alert(total);
		}
	}
//==========valid tradein/upgrde field in shopping cart area===========


//========How to auto-format phone numbers and mask telephone numbers using Javascript===============

var zChar = new Array(' ', '(', ')', '-', '.');
//var maxphonelength = 14;
var maxphonelength = 12;
var phonevalue1;
var phonevalue2;
var cursorposition;

function ParseForNumber1(object){
  phonevalue1 = ParseChar(object.value, zChar);
}

function ParseForNumber2(object){
  phonevalue2 = ParseChar(object.value, zChar);
}

function backspacerUP(object,e) {
  if(e){
    e = e
  } else {
    e = window.event
  }
  if(e.which){
    var keycode = e.which
  } else {
    var keycode = e.keyCode
  }

  ParseForNumber1(object)

  if(keycode >= 48){
    ValidatePhone(object)
  }
}

function backspacerDOWN(object,e) {
  if(e){
    e = e
  } else {
    e = window.event
  }
  if(e.which){
    var keycode = e.which
  } else {
    var keycode = e.keyCode
  }
  ParseForNumber2(object)
}

function GetCursorPosition(){

  var t1 = phonevalue1;
  var t2 = phonevalue2;
  var bool = false
  for (i=0; i<t1.length; i++)
  {
    if (t1.substring(i,1) != t2.substring(i,1)) {
      if(!bool) {
        cursorposition=i
        window.status=cursorposition
        bool=true
      }
    }
  }
}

function ValidatePhone(object){

  var p = phonevalue1

  p = p.replace(/[^\d]*/gi,"")

  if (p.length < 3) {
    object.value=p
  } else if(p.length==3){
    pp=p;
    d4=p.indexOf('(')
    //d5=p.indexOf(')')
	d5=p.indexOf('-')
    if(d4==-1){
      //pp="("+pp;
	  pp=pp;
    }
    if(d5==-1){
      //pp=pp+")";
	  pp=pp+"-";
    }
    object.value = pp;
  } else if(p.length>3 && p.length < 7){
    //p ="(" + p;
	p = p;
    l30=p.length;
    //p30=p.substring(0,4);
	p30=p.substring(0,3);
    //p30=p30+") ";
	p30=p30+"-";

    //p31=p.substring(4,l30);
	p31=p.substring(3,l30);
    pp=p30+p31;

    object.value = pp;

  } else if(p.length >= 7){
    //p ="(" + p;
	p = p;
    l30=p.length;
    //p30=p.substring(0,4);
	p30=p.substring(0,3);
    //p30=p30+") ";
	p30=p30+"-";

    //p31=p.substring(4,l30);
	p31=p.substring(3,l30);
    pp=p30+p31;

    l40 = pp.length;
    //p40 = pp.substring(0,9);
	p40 = pp.substring(0,7);
    p40 = p40 + "-"

    //p41 = pp.substring(9,l40);
	p41 = pp.substring(7,l40);
    ppp = p40 + p41;

    object.value = ppp.substring(0, maxphonelength);
  }

  GetCursorPosition()

  if(cursorposition >= 0){
    if (cursorposition == 0) {
      cursorposition = 2
    } else if (cursorposition <= 2) {
      cursorposition = cursorposition + 1
    } else if (cursorposition <= 4) {
      cursorposition = cursorposition + 3
    } else if (cursorposition == 5) {
      cursorposition = cursorposition + 3
    } else if (cursorposition == 6) {
      cursorposition = cursorposition + 3
    } else if (cursorposition == 7) {
      cursorposition = cursorposition + 4
    } else if (cursorposition == 8) {
      cursorposition = cursorposition + 4
      //e1=object.value.indexOf(')');
	  e1=object.value.indexOf('-');
      e2=object.value.indexOf('-');
      if (e1>-1 && e2>-1){
        if (e2-e1 == 4) {
          cursorposition = cursorposition - 1
        }
      }
    } else if (cursorposition == 9) {
      cursorposition = cursorposition + 4
    } else if (cursorposition < 11) {
      cursorposition = cursorposition + 3
    } else if (cursorposition == 11) {
      cursorposition = cursorposition + 1
    } else if (cursorposition == 12) {
      cursorposition = cursorposition + 1
    } else if (cursorposition >= 13) {
      cursorposition = cursorposition
    }

    var txtRange = object.createTextRange();
    txtRange.moveStart( "character", cursorposition);
    txtRange.moveEnd( "character", cursorposition - object.value.length);
    txtRange.select();
  }

}

function ParseChar(sStr, sChar)
{

  if (sChar.length == null)
  {
    zChar = new Array(sChar);
  }
    else zChar = sChar;

  for (i=0; i<zChar.length; i++)
  {
    sNewStr = "";

    var iStart = 0;
    var iEnd = sStr.indexOf(sChar[i]);

    while (iEnd != -1)
    {
      sNewStr += sStr.substring(iStart, iEnd);
      iStart = iEnd + 1;
      iEnd = sStr.indexOf(sChar[i], iStart);
    }
    sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);

    sStr = sNewStr;
  }

  return sNewStr;
}
//========How to auto-format phone numbers and mask telephone numbers using Javascript===============
