function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}
function Validate(){
	//alert("inside");
 	if(document.form1_calc.calculator_location.selectedIndex == 0){
		alert("Please select a location from the list");		
		return false;
	}
	if(document.form1_calc.calculator_currencytype.selectedIndex == 0){
		alert("Please select a currency type from the list");		
		return false;
	}
	if(document.form1_calc.calculator_priceband.selectedIndex == 0)
	{
		alert("Please select a price band from the list");		
		return false;
	}
 	if(SpecialValidate_number(document.form1_calc.calculator_searchfees,"Search Fees")==false) {return false;}
	if(SpecialValidate_number(document.form1_calc.calculator_legalfees,"Legal Fees")==false) {return false;}
	if(SpecialValidate_number(document.form1_calc.calculator_filingfees,"Filing Fees")==false) {return false;}
	if(SpecialValidate_number(document.form1_calc.calculator_registrationfees,"Registration Fees")==false) {return false;}
	document.form1_calc.action = "price.php";
	document.form1_calc.submit();
}
function Validatelocation(){
	if(SpecialValidate(document.frmlocations2.location_name,"Location name")==false) {return false;}
 	document.frmlocations2.action = "location.php";
	document.frmlocations2.submit();
}
function validateback()
{	
	document.frmclassification.action = "registrationProcessStep2.php";
	document.frmclassification.submit();
}
function validateback2()
{	
	document.designSearchclasses.action = "registrationProcessStep1.php";
	document.designSearchclasses.submit();
}
function validateback4()
{	
	document.form1.action = "registrationProcessStep2.php";
	document.form1.submit();
}
function validateback3()
{	
	document.designSearch.action = "index.php";
	document.designSearch.submit();
}
function validatebackconfirm()
{	
	document.frmconfirm.action = "registrationProcessStep3.php";
	document.frmconfirm.submit();
}
 function image() {
	document.frmarticles.article_image.value='';
	alert('Please use Browse button to file upload'); 
	document.frmarticles.article_image.focus();
	return false;
}

function adminValidate(){
	if(SpecialValidate(document.frmadmin.admin_username,"user name")==false) {return false;}
	if(SpecialValidate(document.frmadmin.admin_password,"password")==false) {return false;}
	
	document.frmadmin.action = "changePassword.php";
	document.frmadmin.submit();
}

function popupOpen(){
	window.open("http://www.providesupport.com?messenger=lawdit","mywindow","menubar=0,resizable=1,width=500,height=600");
}

function Check() { 
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(TextValidate(document.designSearch.name,"your name")==false) return false;
	if(document.designSearch.email.value == "")
	{
		alert("Please enter a valid email address\ne.g. username@domainname.com");		
		document.designSearch.email.focus();   	
		return false;		
	}	else if (!filter.test(document.designSearch.email.value)) 	{
		alert("Please enter a valid email address\ne.g. username@domainname.com");
		document.designSearch.email.focus();	   	
		document.designSearch.email.select();
		return false;
	}
	//if(EmailValidate(document.designSearch.email,"email")==false) return false;
	if(TextValidate(document.designSearch.trade,"the trademark")==false) return false;
	if(document.designSearch.logo.value == ""){
		alert("Please upload a logo!");
		return false;
	}
	if(trim(document.designSearch.logo.value)!="")
	{
		var file_type = document.designSearch.logo.value.split(".");
		if(file_type[1]!="jpg" && file_type[1]!="gif" && file_type[1]!="jpeg" && file_type[1]!="JPG" && file_type[1]!="GIF")
		{
			alert("Please upload JPEG or GIF images");
			return false;
		}
	}
	//if(File_Extentsion_Validate(document.designSearch.logo,"logo")== false) return false;
 	document.designSearch.action="process.php";
	document.designSearch.submit();
}

function  Delete(id){
	if(confirm("Are you sure you want to delete this entry")){
		document.frmarticleList.action="articleList.php?action=delete&id="+id;
		document.frmarticleList.submit();
	}
}
function  Deleteprice(id){
	if(confirm("Are you sure you want to delete this entry")){
		document.frmcalculator.action="pricelist.php?action=delete&id="+id;
		document.frmcalculator.submit();
	}
}
function  Deletelocation(id){
	if(confirm("Are you sure you want to delete this entry")){
		document.frmcalculator.action="locationlist.php?action=delete&id="+id;
		document.frmcalculator.submit();
	}
}

function openWindow() {
popupWin=window.open('popup_assistance.htm','country_assistance','width=435,height=525,top=100,left=100','scrollbars=yes')
}

function formSubmit(){
	if(document.frmindex.country.value == 0){
		alert("Please select a location from the list");
		document.frmindex.country.focus();
		return false;
	}
	document.frmindex.action="registrationProcessStep1.php";
	document.frmindex.submit();
}

function frmdesignSearch(){
	//alert("inside");
	//return false;
	if(document.designSearch.calculator_option[0].checked == false && document.designSearch.calculator_option[1].checked == false && document.designSearch.calculator_option[2].checked == false){
		alert("Please choose an option");
		return false;
	}
	document.designSearch.action="registrationProcessStep2.php";
	document.designSearch.submit();
}

function frmdesignSearch2(){
if(document.designSearchclasses.check_count){
		if(document.designSearchclasses.check_count.value == "")
		{
			alert("Please select a class");
			return false;
		}
		document.designSearchclasses.action="registrationProcessStep3.php";
		document.designSearchclasses.submit();
	}
}
function validatecheck_count(check_value)
{
var test = "class"+check_value;
if(document.getElementById("check_count")){
	var availvalue = document.getElementById("check_count").value;
 	if(document.getElementById(test).checked == true) {			
		if(availvalue == "") {
			availvalue = document.getElementById(test).value;
		}else {
			availvalue = availvalue+","+document.getElementById(test).value;
		}				
	}else{
		var hidden_deliver = document.getElementById("check_count").value;
		var availarray = hidden_deliver.split(",");
		var availvalue = "";
		for(var i=0;i<availarray.length;i++) {
			if(availarray[i]!=document.getElementById(test).value) {
				if(availvalue == "") {
					availvalue = availarray[i];
				}else {
					availvalue = availvalue+","+availarray[i];
				}				
			}
		}
	}
	document.getElementById("check_count").value = availvalue;	
}else{
	document.getElementById(test).checked = false;
}
//alert(availvalue);
}
function CheckLogo(){
	if(document.designSearch.getElementById("txttrademark").value == ""){
		document.degignSearch.getElemetById("txttrademark").value = "No Trademark Entered";
	}
	document.designSearch.action="registrationProcessStep5.htm";
	document.designSearch.submit();
}

function trademarkOwner(){
	if(TextValidate(document.designSearch.txtname,"the name")==false) return false;
	if(TextValidate(document.designSearch.txtcompany,"the company")==false) return false;
	if(TextValidate(document.designSearch.txtpostcode,"the postcode")==false) return false;
	if(File_Extentsion_Validate(document.designSearch.logo,"logo")== false) return false;
	if(EmailValidate(document.designSearch.txtemail,"email")==false) return false;
	
	document.designSearch.action="process.php";
	document.designSearch.submit();
}

function changeband()
{		
		window.location.href = "price.php?location="+document.form1_calc.calculator_location.value+"&status=new";
		//document.form1_calc.action = "price.php?location="+document.form1_calc.calculator_location.value;
		//document.form1_calc.submit();

}
function submitform()
{
	document.form1.action="confirm.php";
	document.form1.submit();
}

function Validate_check(){
	if(TextValidate(document.frmconfirm.txtname,"the name")==false) return false;
	if(TextValidate(document.frmconfirm.txttrademark,"the proposed trademark")==false) return false;
	if(trim(document.frmconfirm.logo_image.value)!="")
	{
		var file_type = document.frmconfirm.logo_image.value.split(".");
		var final = file_type.length;
		//alert(file_type[final-1]);
		//return false;
		if(file_type[final-1]!="jpg" && file_type[final-1]!="gif" && file_type[final-1]!="jpeg" && file_type[final-1]!="JPG" && file_type[final-1]!="GIF")
		{
			alert("Please upload JPEG or GIF images");
			return false;
		}
	}
	if(EmailValidate(document.frmconfirm.txtemail,"email")==false) return false;
	document.frmconfirm.action = "confirm-process.php?status=insert";
	document.frmconfirm.submit();
	//Ajax_Check();
}
function Ajax_Check() {
	var xmlhttp = false;
	// If the user is using Mozilla/Firefox/Safari/etc	
	if (window.XMLHttpRequest) {
			//Intiate the object
			xmlhttp = new XMLHttpRequest();
			//xmlhttp.setHeader("Cache-Control", "no-cache");
			//Set the mime type
			//xmlhttp.overrideMimeType('text/xml');
	}
	// If the user is using IE
	else if (window.ActiveXObject) { 
			//Intiate the object
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			//xmlhttp.setHeader("Cache-Control", "no-cache");
			//Http.get(params, callback_args)
	}	
	//Calling 
		var country_final = document.getElementById("country_final").value;		
		var calculator_type = document.getElementById("calculator_type").value;
 		var calculator_classes = document.getElementById("calculator_classes").value;
		var calculator_currency = document.getElementById("calculator_currency").value;
		var calculator_total = document.getElementById("calculator_total").value;
		var name = document.getElementById("txtname").value;
		var email = document.getElementById("txtemail").value;
		var txttrademark = document.getElementById("txttrademark").value;
		var address1 = document.getElementById("txtaddress1").value;
		var address2 = document.getElementById("txtaddress2").value;
		var phone = document.getElementById("txtphone").value;
		var fax = document.getElementById("txtfax").value;
		var postcode = document.getElementById("txtpostcode").value;
		var url = 'insertprocess.php?country_final='+country_final+"&calculator_type="+calculator_type+"&calculator_classes="+calculator_classes+"&calculator_currency="+calculator_currency+"&calculator_total="+calculator_total+"&name="+name+"&txttrademark="+txttrademark+"&email="+email+"&address1="+address1+"&address2="+address2+"&phone="+phone+"&fax="+fax+"&postcode="+postcode;				
		//document.getElementById("temp_url").value = url;
		//alert (url);
		//return false;
 		//Open the URL above "asynchronously" (that's what the "true" is for) using the GET method		
		xmlhttp.open('GET', url, true);
		//Check that the PHP script has finished sending us the result
 		xmlhttp.onreadystatechange = function() {
  			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
 				//Replace the content of the "result" DIV with the result returned by the PHP script
					var response     = xmlhttp.responseText;	
					alert(response);
					return false;
					document.getElementById("cartId").value = response;
 					//document.frmconfirm.action = "https://select-test.worldpay.com/wcc/purchase";
					document.frmconfirm.action = "https://select.worldpay.com/wcc/purchase";
					document.frmconfirm.submit();
 			}
		}
		xmlhttp.send(null);  
}
function validatetemp()
{
	document.frmcontainer.country.value = 1;
	document.frmcontainer.action = "registrationProcessStep1.php";
	document.frmcontainer.submit();
}
function validatedeposit()
{
	if(TextValidate(document.form1_calc.deposit_amount,"Deposit amount")==false) return false;
	if(SpecialValidate_number(document.form1_calc.deposit_amount,"Deposit amount")==false) {return false;}
	document.form1_calc.action="deposit.php";
	document.form1_calc.submit();
}