/*
	TalkShoe Confidential Information
	Copyright (c) 2005 - 2009 
*/

function checkPhone(whichCalled,FormName){
	var phone1=document.getElementById(FormName+':PhoneNumber1').value;
	var phone2=document.getElementById(FormName+':PhoneNumber2').value;
	var phone3=document.getElementById(FormName+':PhoneNumber3').value;
	var phoneMain;
	
	phoneMain=phone1+phone2+phone3;
	document.getElementById(FormName+':PhoneNumber').value=phoneMain;
}

function unStringPhone(FormName){
	var phone1;
	var phone2;
	var phone3;
	var phoneMain;
	
	phoneMain=document.getElementById(FormName+':PhoneNumber').value;
	
	if(phoneMain.length==11){
		phone1=phoneMain.substring(0,4);
		phone2=phoneMain.substring(4,7);
		phone3=phoneMain.substring(7,11);
	}else if(phoneMain.length==10){
		phone1=phoneMain.substring(0,3);
		phone2=phoneMain.substring(3,6);
		phone3=phoneMain.substring(6,10);
	}else{
		phone1="";
		phone2="";
		phone3="";
	}
	
	document.getElementById(FormName+':PhoneNumber1').value=phone1;
	document.getElementById(FormName+':PhoneNumber2').value=phone2;
	document.getElementById(FormName+':PhoneNumber3').value=phone3;
	
}

function phonePinIllegalOld(input) {
var illegal = /\D/gi ;
input.value = input.value.replace(illegal,"") ;
}

function phonePinIllegal(obj){
	var nums="1234567890";
	o=obj;
	
	if(o.value.length==0) return;
	lchar = o.value.substr(o.value.length-1,1);
	if(nums.indexOf(lchar)==-1) o.value = o.value.substr(0,o.value.length-1);
}

function goPinSelection(fieldName){

document.getElementById('pinCreateForm:mainPinCreateText6').style.height = '50px';

	if(((fieldName.name=="pinCreateForm:PINSelector2") 
	&& (document.getElementById('pinCreateForm:PINSelector2').checked==true))
	|| (fieldName.id=="pinCreateForm:NumberPIN")){
		document.getElementById('pinCreateForm:TalkShoePin').value='';
		document.getElementById('pinCreateForm:PhonePIN').value='';
		document.getElementById('pinCreateForm:PINSelector1').checked=false;
		document.getElementById('pinCreateForm:PINSelector2').checked=true;		
		document.getElementById('pinCreateForm:PinConfirmText1a').style.color='#4B9AE0';
		document.getElementById('pinCreateForm:PinConfirmText1b').style.color='#FFFFFF';
		document.getElementById('pinCreateForm:PhonePIN').style.backgroundColor='#CFE7FF';
		document.getElementById('pinCreateForm:NumberPIN').style.backgroundColor='#FFFFFF';
		document.getElementById('pinCreateForm:PhonePIN').style.borderWidth='0px';
		document.getElementById('pinCreateForm:NumberPIN').style.borderWidth='1px';
		$("span.PinConfirmText3:hidden").slideDown("slow");
	}else if(((fieldName.name=="pinCreateForm:PINSelector1") 
	&& (document.getElementById('pinCreateForm:PINSelector1').checked==true))
	|| (fieldName.id=="pinCreateForm:PhonePIN")){
		document.getElementById('pinCreateForm:TalkShoePin').value='';
		document.getElementById('pinCreateForm:NumberPIN').value='';
		document.getElementById('pinCreateForm:PINSelector1').checked=true;
		document.getElementById('pinCreateForm:PINSelector2').checked=false;		
		document.getElementById('pinCreateForm:PinConfirmText1a').style.color='#FFFFFF';
		document.getElementById('pinCreateForm:PinConfirmText1b').style.color='#4B9AE0';
		document.getElementById('pinCreateForm:PhonePIN').style.backgroundColor='#FFFFFF';
		document.getElementById('pinCreateForm:NumberPIN').style.backgroundColor='#CFE7FF';
		document.getElementById('pinCreateForm:PhonePIN').style.borderWidth='1px';
		document.getElementById('pinCreateForm:NumberPIN').style.borderWidth='0px';
		$("span.PinConfirmText3:visible").slideUp("slow");
	}else{
		document.getElementById('pinCreateForm:TalkShoePin').value='';
		document.getElementById('pinCreateForm:NumberPIN').value='';
		document.getElementById('pinCreateForm:PhonePIN').value='';	
		document.getElementById('pinCreateForm:PinConfirmText1a').style.color='#FFFFFF';
		document.getElementById('pinCreateForm:PinConfirmText1b').style.color='#FFFFFF';
		document.getElementById('pinCreateForm:PhonePIN').style.backgroundColor='#FFFFFF';
		document.getElementById('pinCreateForm:NumberPIN').style.backgroundColor='#FFFFFF';
		document.getElementById('pinCreateForm:PhonePIN').style.borderWidth='1px';
		document.getElementById('pinCreateForm:NumberPIN').style.borderWidth='1px';
		document.getElementById('pinCreateForm:PINSelector1').checked=false;
		document.getElementById('pinCreateForm:PINSelector2').checked=false;
		$("span.PinConfirmText3:visible").slideUp("slow");
	}
		
		if((document.getElementById('pinCreateForm:PINSelector1').checked==false)
		&& (document.getElementById('pinCreateForm:PINSelector2').checked==false)){
		 	document.getElementById('pinCreateForm:TalkShoePin').value='';
		 }
		
}

function pinUpdateHidden(formName,selectorName,newFieldPin,fieldToUpdatePin){
	var newPin=document.getElementById(formName+':'+newFieldPin).value;
	var selectorCheck=document.getElementById(formName+':'+selectorName);
	
	if(selectorCheck.checked==true){
		document.getElementById(formName+':'+fieldToUpdatePin).value=newPin;
		return true;
	}else{
		document.getElementById(formName+':'+fieldToUpdatePin).value='';
		return true;
	}
}

function pinUpdateHiddenSaved(formName,newFieldPin,fieldToUpdatePin){
	var newPinSaved=document.getElementById(formName+':'+newFieldPin).value;
	document.getElementById(formName+':'+fieldToUpdatePin).value=newPinSaved;
}

function checkPinValidation(){
	var tsPin=document.getElementById('pinCreateForm:TalkShoePin').value;
	var pinSelector1=document.getElementById('pinCreateForm:PINSelector1').checked;
	var pinSelector2=document.getElementById('pinCreateForm:PINSelector2').checked;
	var numberPINVal=document.getElementById('pinCreateForm:NumberPIN').value;
	var phonePINVal=document.getElementById('pinCreateForm:PhonePIN').value;	
	
	if((pinSelector1==false) && (pinSelector2==false)){
		errorPop('Please enter a 10 digit number for your TalkShoe Pin.');
		return false;
	}
	
	if(tsPin==''){
		if((pinSelector1 == true) && (phonePINVal != '') && (phonePINVal.length == '10')){
			return pinUpdateHidden('pinCreateForm','PINSelector1','PhonePIN','TalkShoePin');
		}else if((pinSelector2 == true) && (numberPINVal != '') && (numberPINVal.length == '10')){
			return pinUpdateHidden('pinCreateForm','PINSelector2','NumberPIN','TalkShoePin');
		}else{
			errorPop('Please enter a 10 digit number for your TalkShoe Pin.');
			return false;
		}
	}else{
		return true;
	}
}

function checkPinEditValidation(){
	var tsPin=document.getElementById('pinCreateForm:TalkShoePin').value;
	
	if(tsPin==''){
		errorPop('Please enter a 10 digit number for your TalkShoe Pin.');
		return false;
	}else if(tsPin.length!='10'){
		errorPop('Please enter a 10 digit number for your TalkShoe Pin.');
		return false;
	}else{
		return true;
	}
}

function goPinEdit(){
	var savedTR=document.getElementById('pinCreateForm:mainPinCreateSavedTR');
	var editTR=document.getElementById('pinCreateForm:mainPinCreateSavedEditTR');
	var editBtn=document.getElementById('pinCreateForm:mainPinCreateButtonEDIT');
	
	if(editTR.style.display = "none"){
		savedTR.style.display = "none";
		editTR.style.display = "";
		editBtn.style.display = "";
	}else{
		savedTR.style.display = "";
		editTR.style.display = "none";
		editBtn.style.display = "none";
	}

}

function goPinInstructions(){
 var popWidth = "520px";
 var popHeight = "310px";
		window.open("/se/help/whatsAPin.html", "WhatPin", "resizable=no,toolbar=no, location=no, scrollbars=no, menubar=no, status=no, titlebar=no, height="+popHeight+", width="+popWidth+", top=50 left=50");
}

function clearPinValues(){
		document.getElementById('pinCreateForm:TalkShoePin').value='';
		document.getElementById('pinCreateForm:PhonePIN').value='';
		document.getElementById('pinCreateForm:NumberPIN').value='';
		document.getElementById('pinCreateForm:PhonePIN').style.backgroundColor='#FFFFFF';
		document.getElementById('pinCreateForm:NumberPIN').style.backgroundColor='#FFFFFF';
		document.getElementById('pinCreateForm:PhonePIN').style.borderWidth='1px';
		document.getElementById('pinCreateForm:NumberPIN').style.borderWidth='1px';
		document.getElementById('pinCreateForm:PINSelector1').checked=false;
		document.getElementById('pinCreateForm:PINSelector2').checked=false;
}