function launchDrawing(sDrawingNo, sVault,sAddress)
{
	if(sDrawingNo != ""){
		sDrawingNo = sDrawingNo.replace('.','');
	}

	var ssURL = sAddress+"drawingsearchcomponent/drawing.do?invoke=viewDrawingSearchResults&drawingNo=" +sDrawingNo+"&vault="+sVault ;
	drawingwin = window.open(ssURL, "Drawing","scrollbars=yes,resizable=yes,toolbar=no,status=no,height=450,width=705");
	if(drawingwin.opener == null)
		drawingwin.opener = self;
}
function viewProductDetails(sMotorNo,sProductType)
{
	document.SearchForm.motorNo.value = sMotorNo;
	document.SearchForm.productType.value = sProductType;
	//alert(document.SearchForm.motorNo.value);
	document.SearchForm.invoke.value = "viewProductDetails";
	document.SearchForm.submit();
	//window.open("/leeson/searchproduct.do?invoke=viewProductDetails&motorNo="+sMotorNo);

}
//adde by Subhakar
function getAreaResults(areaName) {
	if (areaName == 'Canada' || areaName == 'Europe' || areaName == 'US' ) {
	   	//document.serviceCenterForm.invoke.value = "viewServiceCenterLocator";
	   // document.serviceCenterForm.area.value = areaName;
	    document.location = "servicecenter.do?invoke=viewServiceCenterLocator#"+areaName;
	}else {
	    //document.serviceCenterForm.area.value = areaName;
		//document.serviceCenterForm.submit();
		document.location = "servicecenter.do?invoke=viewSearchResults&area="+areaName;
	}

}

function getServiceCentersByState(areaName, stateName) {

	if (stateName != "") {
		if (stateName == "zip") {
			//document.location = "servicecenter.do?invoke=viewSearchResults&area=US&zipcode="+stateName;
			//document.serviceCenterForm.invoke.value = "viewSearchResults";
			//document.serviceCenterForm.submit();
			document.location = "servicecenter.do?invoke=viewSearchResults&country=US&zipcode="+document.serviceCenterForm.zipcode.value;

		}else {
			document.location = "servicecenter.do?invoke=viewSearchResults&country="+areaName+"&state="+stateName;
		}	
	}
}

function getServiceCentersByZipCode() {
	document.location = "servicecenter.do?invoke=viewZipCodeSearchResults&zipcode="+document.serviceCenterForm.zipcode.value+"&miles="+document.serviceCenterForm.miles.value;
   
}
function getServiceCentersByCountry(areaName, countryName) {

	document.location = "servicecenter.do?invoke=viewSearchResults&area="+areaName+"&country="+countryName;
}
function submitAskLesson(){

	var phoneVal = Trim(document.ContactForm.askLeesonPhone.value);
	var subPhoneVal = phoneVal.substring(8,0).toLowerCase();
	if (subPhoneVal != "" && subPhoneVal == "(include")
		document.ContactForm.askLeesonPhone.value = "";		
	
	document.ContactForm.countryName.value = Trim(document.ContactForm.askLeesonCountry.options[document.ContactForm.askLeesonCountry.selectedIndex].text);
	
	if (Trim(document.ContactForm.askLeesonCountry.value).toUpperCase() == "US" 
			|| Trim(document.ContactForm.askLeesonCountry.value).toUpperCase() == "CA"){
			
		document.ContactForm.stateName.value = Trim(document.ContactForm.askLeesonState.options[document.ContactForm.askLeesonState.selectedIndex].text);
	}
	
 	var faxVal = Trim(document.ContactForm.askLeesonFax.value);
	var subFaxVal = faxVal.substring(8,0).toLowerCase();
	if (subFaxVal != "" && subFaxVal == "(include")
		document.ContactForm.askLeesonFax.value = "";		

	var specialCharacter = /^[a-zA-Z0-9()-.,&]+(\s([a-zA-Z0-9()-])+)*$/;				
	if (document.ContactForm.askLeesonRequestType.value == "0"){
		alert("Please select Request Type");
		document.ContactForm.askLeesonRequestType.focus();
	}else if (Trim(document.ContactForm.askLeesonName.value) == ""){
		alert("Please enter Your Name");
		document.ContactForm.askLeesonName.focus();
	}else if (Trim(document.ContactForm.askLeesonName.value) != "" && ! specialCharacter.test(Trim(document.ContactForm.askLeesonName.value)) ){
		alert("Please enter valid Name");
		document.ContactForm.askLeesonName.focus();
	}else if (Trim(document.ContactForm.askLeesonEmailId.value) == ""){
		alert("Please enter E-mail Address");
		document.ContactForm.askLeesonEmailId.focus();
	}else if ( ! isValidEmail(document.ContactForm.askLeesonEmailId)){			
		document.ContactForm.askLeesonEmailId.focus();
	}else if (Trim(document.ContactForm.askLeesonTitle.value) == ""){
		alert("Please enter Position/Title");
		document.ContactForm.askLeesonTitle.focus();
	}else if (Trim(document.ContactForm.askLeesonTitle.value) != "" && ! specialCharacter.test(Trim(document.ContactForm.askLeesonTitle.value)) ){
		alert("Please enter valid Position/Title");
		document.ContactForm.askLeesonTitle.focus();
	}else if (Trim(document.ContactForm.askLeesonCompany.value) == ""){
		alert("Please enter Company");
		document.ContactForm.askLeesonCompany.focus();
	}else if (Trim(document.ContactForm.askLeesonAddress1.value) == ""){
		alert("Please enter Address");
		document.ContactForm.askLeesonAddress1.focus();
	}else if (Trim(document.ContactForm.askLeesonCity.value) == ""){
		alert("Please enter City");
		document.ContactForm.askLeesonCity.focus();
	}else if (Trim(document.ContactForm.askLeesonCity.value) != "" && ! specialCharacter.test(Trim(document.ContactForm.askLeesonCity.value)) ){
		alert("Please enter valid City");
		document.ContactForm.askLeesonCity.focus();
	}else if (document.ContactForm.askLeesonCountry.value == "0"){
		alert("Please select Country");
		document.ContactForm.askLeesonCountry.focus();
	}else if (document.ContactForm.askLeesonState.value == "0" && Trim(document.ContactForm.askLeesonOtherState.value) == ""){
		if (Trim(document.ContactForm.askLeesonCountry.value).toUpperCase() == "US" || Trim(document.ContactForm.askLeesonCountry.value).toUpperCase() == "CA"){
			alert("Please select State");
			document.ContactForm.askLeesonState.focus();
		}else{
			alert("Please enter valid Other location");
			document.ContactForm.askLeesonOtherState.focus();
		}
	}else if (document.ContactForm.askLeesonState.value != "0" && Trim(document.ContactForm.askLeesonOtherState.value) != ""
								&& ! specialCharacter.test(Trim(document.ContactForm.askLeesonOtherState.value))){
		alert("Please enter valid Other location");
		document.ContactForm.askLeesonOtherState.focus();
	}else if (Trim(document.ContactForm.askLeesonZipCode.value) == ""){
		alert("Please enter Zip Code");
		document.ContactForm.askLeesonZipCode.focus();
	}else if (isNaN(document.ContactForm.askLeesonZipCode.value)){
		alert("Please enter valid Zip Code");
		document.ContactForm.askLeesonZipCode.focus();
	}else if ( ( Trim(document.ContactForm.askLeesonCountry.value).toUpperCase() == "US" 
					|| Trim(document.ContactForm.askLeesonCountry.value).toUpperCase() == "CA")
				 && (Trim(document.ContactForm.askLeesonZipCode.value).length < 5) 	){
		alert("Zip code must be greater than 5 digits");
		document.ContactForm.askLeesonZipCode.focus();
	}else if (Trim(document.ContactForm.askLeesonPhone.value) == "" || subPhoneVal == "(include" ){
		alert("Please enter Telephone");
		document.ContactForm.askLeesonPhone.focus();
	}else if (Trim(document.ContactForm.askLeesonReplyType.value) == "0"){
		alert("Please select Reply Type");
		document.ContactForm.askLeesonReplyType.focus();
	}else if(Trim(document.ContactForm.askLeesonComments.value) == ""){
	    alert("Please enter your message");
		document.ContactForm.askLeesonComments.focus();
	}else{
		document.ContactForm.submit();
	}
}


function submitFeedback(){
	var specialCharacter = /^[a-zA-Z0-9()-.,&]+(\s([a-zA-Z0-9()-])+)*$/;	
	
	if (Trim(document.ContactForm.askLeesonName.value) == ""){
		alert("Please enter Name");
		document.ContactForm.askLeesonName.focus();
	}else if (Trim(document.ContactForm.askLeesonName.value) != "" && ! specialCharacter.test(Trim(document.ContactForm.askLeesonName.value)) ){
		alert("Please enter valid Name");
		document.ContactForm.askLeesonName.focus();
	}else if (Trim(document.ContactForm.askLeesonEmailId.value) == ""){
		alert("Please enter E-mail Address");
		document.ContactForm.askLeesonEmailId.focus();
	}else if ( ! isValidEmail(document.ContactForm.askLeesonEmailId)){		
		document.ContactForm.askLeesonEmailId.focus();
	}else if (Trim(document.ContactForm.askLeesonCity.value) == ""){
		alert("Please enter City");
		document.ContactForm.askLeesonCity.focus();
	}else if (Trim(document.ContactForm.askLeesonCity.value) != "" && ! specialCharacter.test(Trim(document.ContactForm.askLeesonCity.value)) ){
		alert("Please enter valid City");
		document.ContactForm.askLeesonCity.focus();
	}else if (Trim(document.ContactForm.askLeesonSubject.value) == "0"){
		alert("Please select Subject");
		document.ContactForm.askLeesonSubject.focus();
	}else if (Trim(document.ContactForm.askLeesonComments.value) == ""){
		alert("Please enter Comments");
		document.ContactForm.askLeesonComments.focus();
	}else{
		document.ContactForm.submit();
	}
}


function clearOption(targetObjOriginal){
	var mySplitResult = targetObjOriginal.split(",");
	
	for(i = 0; i < mySplitResult.length; i++){
		var splitObject = mySplitResult[i];		
		var targetObj = document.getElementById(mySplitResult[i]);				
		var mySplitResult1 = splitObject.split(":");
		if (mySplitResult1.length > 0){
			var targetObj1 = document.getElementById(mySplitResult1[0]);

			if ( targetObj1.type=="select-one" ) {
				targetObj1.options.length=0;
            	targetObj1.options[0] = new Option("Select"); 
    	    	targetObj1.options[0].value = "";
    	    	targetObj1.options[0].selected;
			} else {
		    	targetObj1.value='';
			}					
		}
	}
}


function onCountryChange(countryObj, targetObjs, toggleName){		
	if (Trim(countryObj.value) != "" &&  Trim(countryObj.value) != "0") {			
		if (Trim(countryObj.value).toUpperCase() == "US" || Trim(countryObj.value).toUpperCase() == "CA"){			
			clearOption(targetObjs);					
			var url = "contact.do?invoke=loadStateLookUp&selectedOption=" + Trim(countryObj.value)+ "&targetObjects=" +Trim(targetObjs);
			data = "";
			data += "&selectedOption=" + Trim(countryObj.value)+ "&targetObjects=" +Trim(targetObjs);		
			url += data;
	    	invokeAjaxFunctionality(url, data, toggleName);		
	    }else{
	    	var targetObj = document.getElementById(targetObjs);
	    	if(targetObj != null)	
		    	targetObj.disabled = true;
	    	clearOption(targetObjs);
	    }
	}else {
         clearOption(targetObjs);
	} 
}

function submitLiterature(){
	var specialCharacter = /^[a-zA-Z0-9()-.,&]+(\s([a-zA-Z0-9()-])+)*$/;		
	var isChecked = false;
	
	var phoneVal = Trim(document.ContactForm.askLeesonPhone.value);
	var subPhoneVal = phoneVal.substring(8,0).toLowerCase();
	if (subPhoneVal != "" && subPhoneVal == "(include")
		document.ContactForm.askLeesonPhone.value = "";
	
	document.ContactForm.countryName.value = Trim(document.ContactForm.askLeesonCountry.options[document.ContactForm.askLeesonCountry.selectedIndex].text);
	
	if (Trim(document.ContactForm.askLeesonCountry.value).toUpperCase() == "US" 
			|| Trim(document.ContactForm.askLeesonCountry.value).toUpperCase() == "CA"){
			
		document.ContactForm.stateName.value = Trim(document.ContactForm.askLeesonState.options[document.ContactForm.askLeesonState.selectedIndex].text);
	}	
	
 	var faxVal = Trim(document.ContactForm.askLeesonFax.value);
	var subFaxVal = faxVal.substring(8,0).toLowerCase();
	if (subFaxVal != "" && subFaxVal == "(include")
		document.ContactForm.askLeesonFax.value = "";	
		
	for (var i=0;i<document.ContactForm.catalog.length;i++)  {	
		if (document.ContactForm.catalog[i].checked){
			if (document.ContactForm.catalog[i].value == "Other"){
				if (Trim(document.ContactForm.otherCatalog.value) == ""){
					alert("Please enter Other Bulletin value");
					document.ContactForm.otherCatalog.focus();	
					return;				
				}
			}
			isChecked = true;
		}
	}
	
	
	if (! isChecked){
		for (var i=0;i<document.ContactForm.bulletins.length;i++)  {	
			if (document.ContactForm.bulletins[i].checked){
				if (document.ContactForm.bulletins[i].value == "Other"){
					if (Trim(document.ContactForm.otherBulletin.value) == ""){
						alert("Please enter Other Subject value");
						document.ContactForm.otherBulletin.focus();	
						return;				
					}
				}
				isChecked = true;
			}
		}
	}else{
		for (var i=0;i<document.ContactForm.bulletins.length;i++)  {	
			if (document.ContactForm.bulletins[i].checked){
				if (document.ContactForm.bulletins[i].value == "Other"){
					if (Trim(document.ContactForm.otherBulletin.value) == ""){
						alert("Please enter Other Subject value");
						document.ContactForm.otherBulletin.focus();	
						return;				
					}
				}				
			}
		}
	}
	
	if (! isChecked){
		alert("Please select atleast one Bulletin/Subject value");
	}else if (Trim(document.ContactForm.askLeesonName.value) == ""){
		alert("Please enter Name");
		document.ContactForm.askLeesonName.focus();
	}else if (Trim(document.ContactForm.askLeesonName.value) != "" && ! specialCharacter.test(Trim(document.ContactForm.askLeesonName.value)) ){
		alert("Please enter valid Name");
		document.ContactForm.askLeesonName.focus();
	}else if ( ! isValidEmail(document.ContactForm.askLeesonEmailId)){				
		document.ContactForm.askLeesonEmailId.focus();
	}else if (Trim(document.ContactForm.askLeesonCompany.value) == ""){
		alert("Please enter Company");
		document.ContactForm.askLeesonCompany.focus();
	}else if (Trim(document.ContactForm.askLeesonAddress1.value) == ""){
		alert("Please enter Address");
		document.ContactForm.askLeesonAddress1.focus();
	}else if (Trim(document.ContactForm.askLeesonCity.value) == ""){
		alert("Please enter City");
		document.ContactForm.askLeesonCity.focus();
	}else if (Trim(document.ContactForm.askLeesonCity.value) != "" && ! specialCharacter.test(Trim(document.ContactForm.askLeesonCity.value)) ){
		alert("Please enter valid City");
		document.ContactForm.askLeesonCity.focus();
	}else if (document.ContactForm.askLeesonCountry.value == "0"){
		alert("Please select Country");
		document.ContactForm.askLeesonCountry.focus();
	}else if (document.ContactForm.askLeesonState.value == "0" && Trim(document.ContactForm.askLeesonOtherState.value) == ""){
		if (Trim(document.ContactForm.askLeesonCountry.value).toUpperCase() == "US" || Trim(document.ContactForm.askLeesonCountry.value).toUpperCase() == "CA"){
			alert("Please select State");
			document.ContactForm.askLeesonState.focus();
		}else{
			alert("Please enter valid Other location ");
			document.ContactForm.askLeesonOtherState.focus();
		}
	}else if (document.ContactForm.askLeesonState.value != "0" && Trim(document.ContactForm.askLeesonOtherState.value) != ""
								&& ! specialCharacter.test(Trim(document.ContactForm.askLeesonOtherState.value))){
		alert("Please enter valid Other location ");
		document.ContactForm.askLeesonOtherState.focus();
	}else if (Trim(document.ContactForm.askLeesonZipCode.value) == ""){
		alert("Please enter Zip Code ");
		document.ContactForm.askLeesonZipCode.focus();
	}else{
		document.ContactForm.submit();
	}	
}

function distributor_loading(){
document.getElementById('load').style.display="block";

}


function salesoffice_loading(){
	if(Trim(document.salesOfficeForm.zipcode.value)== "" ){
	 alert("Please enter the Zip Code");
	 document.salesOfficeForm.zipcode.focus();
	}else{
		if(isNumeric(document.salesOfficeForm.zipcode.value)){
		document.getElementById('load').style.display="block";
  		document.salesOfficeForm.invoke.value="viewSalesOfficeDetailsByZipcode";
        document.salesOfficeForm.submit();
		 }else{
		 	alert("Please enter the valid Zip Code");
		 	document.salesOfficeForm.zipcode.focus();
		 }
		}
}

function onUSLocationChange(locationCode){
    if(document.salesOfficeForm.uscanadaId.value != 0){
        document.salesOfficeForm.internationalId.value=0;
        document.salesOfficeForm.operation.value="added";
        document.salesOfficeForm.locationCode.value=locationCode.value;
        document.salesOfficeForm.submit();
    }else{
        document.salesOfficeForm.internationalId.value=0;
        document.salesOfficeForm.operation.value="deleted";
        document.salesOfficeForm.locationCode.value=locationCode.value;
        document.salesOfficeForm.submit();
    }
}

function isNumeric(val){
    return(parseFloat(val,10)==(val*1));
}


function onInternationalLocationChange(locationCode){
     if(document.salesOfficeForm.internationalId.value !=0){
         document.salesOfficeForm.uscanadaId.value=0;    
         document.salesOfficeForm.operation.value="added";
         document.salesOfficeForm.locationCode.value=locationCode.value;
         document.salesOfficeForm.submit();
     }else{
        document.salesOfficeForm.uscanadaId.value=0;  
        document.salesOfficeForm.operation.value="deleted";
        document.salesOfficeForm.locationCode.value=locationCode.value;
        document.salesOfficeForm.submit();
    }
     
     
}

function textKey(charLimit) 
{
	supportsKeys = true ;
	calcCharLeft(charLimit);
}

function calcCharLeft(charLimit) 
{
	clipped = false;
	lenUSig = 0;
	maxLength = charLimit;
	if (document.getElementById('askLeesonComments').value.length > maxLength) 
	{ 
		document.getElementById('askLeesonComments').value = document.getElementById('askLeesonComments').value.substring(0,maxLength);
		charleft = 0;
		clipped = true;
	} else 
	{
		charleft = maxLength - document.getElementById('askLeesonComments').value.length;
	}
	document.getElementById('msgCL').value = charleft;
	return clipped;
}

function isEnterKey(evt, pcode )
    {
       var charCode = (evt.which) ? evt.which : event.keyCode
       if(charCode==13)
       {
        if(pcode==1){
        document.serviceCenterForm.invoke.value="viewZipCodeSearchResults";
        document.serviceCenterForm.submit();
        }
        
       }
    }

    
function submitContactUs(){
	
	var specialCharacter = /^[a-zA-Z0-9()-.,&]+(\s([a-zA-Z0-9()-])+)*$/;	
	
	if (Trim(document.ContactForm.askLeesonName.value) == ""){
		alert("Please enter Name");
		document.ContactForm.askLeesonName.focus();
	}else if (Trim(document.ContactForm.askLeesonName.value) != "" && ! specialCharacter.test(Trim(document.ContactForm.askLeesonName.value)) ){
		alert("Please enter valid Name");
		document.ContactForm.askLeesonName.focus();
	}else if (Trim(document.ContactForm.askLeesonTitle.value) == ""){
		alert("Please enter Title");
		document.ContactForm.askLeesonTitle.focus();
	}else if (Trim(document.ContactForm.askLeesonTitle.value) != "" && ! specialCharacter.test(Trim(document.ContactForm.askLeesonTitle.value)) ){
		alert("Please enter valid Title");
		document.ContactForm.askLeesonTitle.focus();
	}else if (Trim(document.ContactForm.askLeesonCompany.value) == ""){
		alert("Please enter Company Name");
		document.ContactForm.askLeesonCompany.focus();
	}else if (Trim(document.ContactForm.askLeesonAddress1.value) == ""){
		alert("Please enter Street Address");
		document.ContactForm.askLeesonAddress1.focus();
	}else if (Trim(document.ContactForm.askLeesonCity.value) == ""){
		alert("Please enter City");
		document.ContactForm.askLeesonCity.focus();
	}else if (Trim(document.ContactForm.askLeesonCity.value) != "" && ! specialCharacter.test(Trim(document.ContactForm.askLeesonCity.value)) ){
		alert("Please enter valid City");
		document.ContactForm.askLeesonCity.focus();
	}else if (Trim(document.ContactForm.askLeesonState.value) == ""){
		alert("Please select State");
		document.ContactForm.askLeesonState.focus();
	}else if (Trim(document.ContactForm.askLeesonZipCode.value) == ""){
		alert("Please enter Zip Code");
		document.ContactForm.askLeesonZipCode.focus();
	}else if (Trim(document.ContactForm.askLeesonComments.value) == ""){
		alert("Please enter Comments");
		document.ContactForm.askLeesonComments.focus();
	}else{
		document.ContactForm.submit();
	}
}    
