var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
	if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
	else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';

	win=window.open(mypage,myname,settings);
}


function clearText(field){
		if (field.defaultValue == field.value) field.value = '';
		else if (field.value == '') field.value = field.defaultValue;
	}
	
	
	function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=300,left = 426,top = 232');");
	}
	
	/**
	 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
	 */
	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 validateContact(){
		var full_name = window.document.getElementById('ContactFullName');
		var subject = window.document.getElementById('ContactSubject');
		var email = window.document.getElementById('ContactEmail');
		var county = window.document.getElementById('ContactCounty');
		var comments = window.document.getElementById('ContactComments');
		
		if (full_name.value == ''){		
			alert("Please enter Full Name");
			full_name.focus();
			return false;
	
		} else if (subject.value == ''){		
			alert("Please enter Subject");
			subject.focus();
			return false;	
	
		} else if (email.value == ''){		
			alert("Please enter Email Address");
			email.focus();
			return false;	
	
		} else if (echeck(email.value)==false){
			alert("Please enter valid Email Address");
			email.focus();
			return false;			
			
		} else if (comments.value == ''){
			alert("Please enter Comments");
			comments.focus();
			return false;	
		}
	
	return true;	
	}
	
	
	
	/*function validatesignupform(){			
		var password = window.document.getElementById('MemberSignupPassword');
		var confirm_password = window.document.getElementById('MemberSignupConfirmPassword');
		var agree = window.document.getElementById('MemberAgree');	
		
		if (agree.checked == false){
			alert("Please agree to Terms and Conditions to proceed");
			return false;		
		}
	
		if (password.value != confirm_password.value) {
			alert("Passwords mismatch. Please enter correct password");
			return false;
		}
		
		return true;
	}*/


	function validateChangePassword(){
		var current_password = window.document.getElementById('MemberCurrentPassword');
		var new_password = window.document.getElementById('MemberNewPassword');
		var confirm_new_password = window.document.getElementById('MemberConfirmNewPassword');	
		
		if (current_password.value == '') {
			alert("Please enter Current password");
			current_password.focus();
			return false;
		}

		if (new_password.value == '') {
			alert("Please enter New password");
			new_password.focus();
			return false;
		}

		if (confirm_new_password.value == '') {
			alert("Please enter Confirm New password");
			confirm_new_password.focus();
			return false;
		}

		if (new_password.value != confirm_new_password.value) {
			alert("New Passwords mismatch. Please enter same New password and Confirm New Password");
			return false;
		}
		
		return true;
	}


	function validatecashierform(){
		var password = window.document.getElementById('MemberPassword');
		var confirm_password = window.document.getElementById('MemberConfirmPassword');

		if (password == '') {
			alert("Please enter Password");
			return false;
		}

		if (confirm_password == '') {
			alert("Please enter Confirm Password");
			return false;
		}

		if (password.value != confirm_password.value) {
			alert("Passwords mismatch. Please enter same passwords");
			return false;
		}
		
		return true;
	}


	function validatesubagentform(){
		var password = window.document.getElementById('MemberPassword');
		var confirm_password = window.document.getElementById('MemberConfirmPassword');

		if (password == '') {
			alert("Please enter Password");
			return false;
		}

		if (confirm_password == '') {
			alert("Please enter Confirm Password");
			return false;
		}

		if (password.value != confirm_password.value) {
			alert("Passwords mismatch. Please enter same passwords");
			return false;
		}
		
		return true;
	}


	function textCounter(field, countfield, maxlimit) {
		if (field.value.length > maxlimit) // if the current length is more than allowed
			field.value =field.value.substring(0, maxlimit); // don't allow further input
		else
			countfield.value = maxlimit - field.value.length;
	}


  /*function submitSignupForm(){
		window.document.getElementById('MemberDo').value = 'save';	
		window.document.getElementById('MemberSignupForm').submit();	
		TransactionTransactionsummaryForm
	}*/

	function validatesignupform(){			
		var password = window.document.getElementById('MemberSignupPassword');
		var confirm_password = window.document.getElementById('MemberSignupConfirmPassword');
		var agree = window.document.getElementById('MemberAgree');		
		
		if (password == '') {
			alert("Please enter Password");
			password.focus();
			return false;
		}

		if (confirm_password == '') {
			alert("Please enter Confirm Password");
			confirm_password.focus();
			return false;
		}

		if (password.value != confirm_password.value) {
			alert("Passwords mismatch. Please enter correct passwords.");
			confirm_password.focus();
			return false;
		}
		
		if (agree.checked == false){
			alert("Please agree with Terms and Conditions to proceed.");
			return false;		
		}
	
		//return true;
		window.document.getElementById('MemberDo').value = 'save';	
		window.document.getElementById('MemberSignupForm').submit();			
	}

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 validateAddCustomerform(option){
		// Option 1 = Save n Use
		// Option 2 = Save
		if (option == 1){
			window.document.getElementById('MemberDo').value = 'savenuse';		
		} else if (option == 2){
			window.document.getElementById('MemberDo').value = 'save';	
		}		
		window.document.getElementById('MemberAddnewcustomerForm').submit();			
	}



	function validateTransactionform(){
		var paymentMethodObj = document.getElementById('TransactionPaymentMethod');
		var paymentMethod = paymentMethodObj.options[paymentMethodObj.selectedIndex] ;
		var ref_no = document.getElementById('TransactionReferenceNumber');	
		var companyNameObj = document.getElementById('TransactionPaymentCompany');
		var companyNameObj = companyNameObj.options[companyNameObj.selectedIndex] ;		
		var stationNameObj = document.getElementById('TransactionPaymentStation');
		var stationNameObj = stationNameObj.options[stationNameObj.selectedIndex] ;
		var stationAddress = document.getElementById('TransactionPaymentStationaddress');
		
		var pkrrate = document.getElementById('TransactionPaymentRate');
		var amountfc = document.getElementById('TransactionPaymentAmountfc');
		
			if (paymentMethod.value == 'Credit' && ref_no.value == '' || ref_no.value == null){		
				alert("Please enter Reference Number.");
				ref_no.focus();
				return false;	
			}
			
			if (companyNameObj.value == ''){		
				alert("Please select Company.");
				companyNameObj.focus();
				return false;	
			}
			
			if (stationNameObj.value == ''){		
				alert("Please select Sation.");
				stationNameObj.focus();
				return false;	
			}
			
			if (stationAddress.value == ''){		
				alert("Please enter Station Address.");
				stationAddress.focus();
				return false;	
			}

			if (pkrrate.value == '' || pkrrate.value == null){		
				alert("Please select Company for PKR Rate @.");
				pkrrate.focus();
				return false;	
			}
			
			if (amountfc.value == '' || amountfc.value == null){		
				alert("Please enter Amount F/C (Foreign Currency).");
				amountfc.focus();
				return false;	
			}
			
		var bpaymentMethodObj = document.getElementById('TransactionBeneficiaryPaymentMethod');
		var bpaymentMethod = bpaymentMethodObj.options[bpaymentMethodObj.selectedIndex] ;
		var bcnic2 = document.getElementById('TransactionBeneficiaryCnic2');
		var bbankname = document.getElementById('TransactionBeneficiaryBankname');
		var bbankbranch = document.getElementById('TransactionBeneficiaryBankbranch');
		var baccountno = document.getElementById('TransactionBeneficiaryAccountno');
			if (bpaymentMethod.value == 'Cash' && bcnic2.value == '' || bcnic2.value == null){
				alert("Please enter Beneficiary Info.");
				bcnic2.focus();
				return false;	
				
			} else if (bpaymentMethod.value == 'Bank'){
					if (bbankname.value == ''){
						alert("Please enter Beneficiary Bank Name.");
						bbankname.focus();
						return false;	
					}
					if (bbankbranch.value == ''){
						alert("Please enter Beneficiary Bank Branch.");
						bbankbranch.focus();
						return false;	
					}
					if (baccountno.value == ''){
						alert("Please enter Beneficiary Bank Account Number.");
						baccountno.focus();
						return false;	
					}
			}

		var bphone = document.getElementById('TransactionBeneficiaryPhone');
		var brelationship = document.getElementById('TransactionBeneficiaryRelationship');
			if (bphone.value == ''){
				alert("Please enter Beneficiary Phone Number.");
				bphone.focus();
				return false;	
			}
			if (brelationship.value == ''){
				alert("Please enter Beneficiary Relationship.");
				brelationship.focus();
				return false;	
			}
		
		document.getElementById('TransactionTransactionsummaryForm').submit();	

		}
