/*	Functions written by Jetscram Design (www.jetscram.com)
	for Jetscram clients.
	Copyright 2008. Randy Apuzzo
	*/



/* check for delte */

function confirmDelete(delUrl) {
  if (confirm("Deleting this report will remove it permanently. Delete?")) {
    document.location = delUrl;
  }
}


/* function to clear input fields of text */

function clearText(thefield){
	if (thefield.defaultValue==thefield.value){
	thefield.value = "";
	}
}


/* phone */

function checkPhone(){
	var phone = document.editAccount.phone;
	if(phone.value == "") {
		return true;
	} else {
		var stripped = phone.value.replace(/[\(\)\.\-\ ]/g, '');
		if (!(stripped.length == 10)) {
			alert ("The phone number is the wrong length.\nMake sure you included an area code without the country code\ne.g. 555-555-5555.");
			this.focus();
			return false
		}
	}
	return true;
}



/* check fields for landingpage form */

function checkformLanding(){
	var theurl = document.createLanding.address;
	var checkurl = theurl.value;
	theurl.style.border = "1px #CCC solid";
		theurl.style.padding = "1px";
	
	if ((checkurl == "") || (checkurl == "http://www.mylandingpageaddress.com")){
	    alert('Please enter the Landing Page URL.');
		theurl.style.border = "1px #FF0000 solid";
		theurl.style.padding = "1px";
		return false;
  	}
  
  	if ((document.createLanding.label.value == "") || (document.createLanding.label.value == "Label your analysis report")){
	    alert('Please label your report.');
    	return false;
  	}
	if(checkurl.substr(0,7) !== "http://"){
		checkurl = "http://"+checkurl;
		theurl.value = checkurl;
	}
	 
    var tomatch= /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+:_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+:_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/; 
    
	if (tomatch.test(checkurl)){
    	
    } else {
		window.alert("Invalid URL. Please Re-enter");
		theurl.style.border = "1px #FF0000 solid";
		theurl.style.padding = "1px";
        return false; 
    } 
  return true;
  
}

/* check for proper email format */
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("please check that your email was entered properly")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("please check that your email was entered properly")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("please check that your email was entered properly")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("please check that your email was entered properly")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("please check that your email was entered properly")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("please check that your email was entered properly")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("please check that your email was entered properly")
		    return false
		 }

	 return true					
}

// signup form check
function signupCheck(){
	
	if ((document.signup.passwordConfirm.value == "") || (document.signup.password.value == "")){
	    alert('Please check your passwords match.');
		document.signup.password.focus();
    	return false;
  	} else if (document.signup.name.value == ""){
	    alert('Please enter your name.');
			document.signup.name.focus();
    	return false;
  	} else if (document.signup.email.value == ""){
	    alert('Please enter your email address.');
			document.signup.email.focus();
    	return false;
  	}
  document.signup.submit.disabled = "true";
  return true;
} 



// send contactER form check
function quoteCheck(){
	if ((document.requestquoteCheck.subject.value == "") || (document.requestquoteCheck.description.value == "") || (document.requestquoteCheck.description.value == "Your message here")){
	    alert('Please check that all form fields are complete.');
		//document.requestquoteCheck.description.focus();
    	return false;
  	}
  document.requestquoteCheck.submit.disabled = "true";
  return true;
}


