
function showPic (whichpic) { 
	if (document.getElementById) { 
		document.getElementById("placeholder").src = whichpic.href; 
		document.getElementById("hrefimage").href = whichpic; 
		
		var objHref = document.getElementsByName("hrefimage");
		for (i=0;i < objHref.length; i++)
		{
			if (objHref[i].href == document.getElementById("placeholder").src)
			{
				objHref[i].setAttribute("class", "pink_bold");
				objHref[i].setAttribute("className", "pink_bold");
			}
			else
			{
				objHref[i].setAttribute("class", "purple_bold");
				objHref[i].setAttribute("className", "purple_bold");
			}
		}
		return false; 
	} else { 
		return true; 
	} 
}
function showPic1 (whichpic) { 
	if (document.getElementById) { 
		document.getElementById("placeholder1").src = whichpic.href; 
		document.getElementById("hrefimage1").href = whichpic; 
		
		var objHref = document.getElementsByName("hrefimage1");
		for (i=0;i < objHref.length; i++)
		{
			if (objHref[i].href == document.getElementById("placeholder1").src)
			{
				objHref[i].setAttribute("class", "pink_bold");
				objHref[i].setAttribute("className", "pink_bold");
			}
			else
			{
				objHref[i].setAttribute("class", "purple_bold");
				objHref[i].setAttribute("className", "purple_bold");
			}
		}
		return false; 
	} else { 
		return true; 
	} 
}
function showPic2 (whichpic) { 
	if (document.getElementById) { 
		document.getElementById("placeholder2").src = whichpic.href; 
		document.getElementById("hrefimage2").href = whichpic; 
		
		var objHref = document.getElementsByName("hrefimage2");
		for (i=0;i < objHref.length; i++)
		{
			if (objHref[i].href == document.getElementById("placeholder2").src)
			{
				objHref[i].setAttribute("class", "pink_bold");
				objHref[i].setAttribute("className", "pink_bold");
			}
			else
			{
				objHref[i].setAttribute("class", "purple_bold");
				objHref[i].setAttribute("className", "purple_bold");
			}
		}
		return false; 
	} else { 
		return true; 
	} 
}

function checkfrm_personalised(theForm) {
	  var reason = "";
	  reason += validateFullName(theForm.txtFullName);
	  reason += validateEbayName(theForm.txtEbayName); 
	  reason += validateEmailPers(theForm.txtEmail);
	  reason += validatePhone(theForm.txtPhone);
	  reason += load_image(theForm.uploadedfile);
	  reason += validatetextline1(theForm.textline1);
	  reason += validatetextline2(theForm.textline2);
	
	  if (reason != "") {
		alert("Some fields need correction:\n" + reason);
		return false;
	  }
	  return true;
}

function validateEbayName(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FFFFD2'; 
        error = "You didn't enter your eBay User Name.\n"
		
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function validatetextline1(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FFFFD2'; 
        error = "You didn't enter the first line of text.\n"
		
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function validatetextline2(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FFFFD2'; 
        error = "You didn't enter the second line of text.\n"
		
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function load_image(fld) {
	var error = "";
	var imgpath = fld.value;
	if(imgpath != "") {
		var arr1 = new Array;
		arr1 = imgpath.split("\\");
		var len = arr1.length;
		var img1 = arr1[len-1];
		var filext = img1.substring(img1.lastIndexOf(".")+1);
		
		// Checking Extension
		if(filext == "jpg" || filext == "jpeg" || filext == "gif" || filext == "bmp")
			fld.src = imgpath;
		else {
			error = "Invalid File Format Selected\n";
			fld.style.background = '#FFFFD2'; 
			fld.value = "";
		}
	}
	else {
		error = "Please Select an Image\n";
		fld.style.background = '#FFFFD2'; 
	}
	return error; 
}

function validatequotefields(theForm) {
  var reason = "";
  reason += validateFName(theForm.txtfname);
  reason += validateLName(theForm.txtlname);
  reason += validateCompanyName(theForm.txtcompname);
  reason += validatePhoneSamples(theForm.txtphone);
  reason += validateSamplesEmail(theForm.txtemail);
  //reason += validateFedEx(theForm.txtupsno);
  reason += validateSamplesValidation(theForm.security_code);

  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validatesamplesfields(theForm) {
  var reason = "";
  reason += validateFName(theForm.txtfname);
  reason += validateLName(theForm.txtlname);
  reason += validateCompanyName(theForm.txtcompname);
  reason += validateAddress(theForm.txtaddress1);
  reason += validateCityName(theForm.txtcity);
  reason += validateStateProv(theForm.txtstate);
  reason += validateZip(theForm.txtzip);
  reason += validatePhoneSamples(theForm.txtphone);
  reason += validateSamplesEmail(theForm.txtemail);
  //reason += validateFedEx(theForm.txtupsno);
  reason += validateSamplesValidation(theForm.security_code);

  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function checkfrm(theForm) {
var reason = "";
  reason += validateFullName(theForm.txtFullName);
  reason += validateCompany(theForm.txtCompany);
  reason += validateNewEmail(theForm.txtEmail);
  reason += validatePhone(theForm.txtPhone);
  reason += validateSecCode(theForm.security_code);
 
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}
function validateSecCode(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FFFFD2'; 
        error = "You didn't enter a security code.\n"
		
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateComment(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FFFFD2'; 
        error = "You didn't enter a comment.\n"
		
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateCompany(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FFFFD2'; 
        error = "You didn't enter a company name.\n"
		
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateCompany(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FFFFD2'; 
        error = "You didn't enter a company name.\n"
		
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function validateFName(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.borderColor = "#FF0000";
		error = "You must enter your First Name.\n"
		
    } else {
        fld.style.borderColor = '#999999' ;
    }
    return error;  
}

function validateAddress(fld) {
    var error = "";
    if (fld.value.length == 0) {
        fld.style.borderColor = "#FF0000";
		error = "You must enter your Address.\n"
		
    } else {
        fld.style.borderColor = '#999999' ;
    }
    return error;  
}

function validateCompanyName(fld) {
    var error = "";
    if (fld.value.length == 0) {
        fld.style.borderColor = "#FF0000";
		error = "You must enter your Company Name.\n"
		
    } else {
        fld.style.borderColor = '#999999' ;
    }
    return error;  
}

function validateCityName(fld) {
    var error = "";
    if (fld.value.length == 0) {
        fld.style.borderColor = "#FF0000";
		error = "You must enter your City.\n"
		
    } else {
        fld.style.borderColor = '#999999' ;
    }
    return error;  
}
function validateStateProv(fld) {
    var error = "";
    if (fld.value.length == 0) {
        fld.style.borderColor = "#FF0000";
		error = "You must enter your State/Province.\n"
		
    } else {
        fld.style.borderColor = '#999999' ;
    }
    return error;  
}
function validateZip(fld) {
    var error = "";
    if (fld.value.length == 0) {
        fld.style.borderColor = "#FF0000";
		error = "You must enter your Zip/Postal Code.\n"
		
    } else {
        fld.style.borderColor = '#999999' ;
    }
    return error;  
}
function validateSamplesPhone(fld) {
    var error = "";
    if (fld.value.length == 0) {
        fld.style.borderColor = "#FF0000";
		error = "You must enter your Phone Number.\n"
		
    } else {
        fld.style.borderColor = '#999999' ;
    }
    return error;  
}
function validateEmailPers(fld) {
	var error="";
    var tfld = trim(fld.value);    
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#FFFFD2'; 
        error = "You must enter your Email Address.\n";
		
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#FFFFD2'; 
        error = "Please must enter a valid Email Address.\n";
		
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#FFFFD2'; 
        error = "The email address contains illegal characters.\n";
		
    } else {
        fld.style.background = 'White'; 
    }
	return error;	
}
function validateSamplesEmail(fld) {
   var error="";
    var tfld = trim(fld.value);    
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
         fld.style.borderColor = "#FF0000";
        error = "You must enter your Email Address.\n";
		
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.borderColor = "#FF0000";
        error = "Please must enter a valid Email Address.\n";
		
    } else if (fld.value.match(illegalChars)) {
        fld.style.borderColor = "#FF0000";
        error = "The email address contains illegal characters.\n";
		
    } else {
        fld.style.borderColor = '#999999' ;
    }
	return error;
}
function validateFedEx(fld) {
    var error = "";
    if (fld.value.length == 0) {
        fld.style.borderColor = "#FF0000";
		error = "You must enter your FedEx/UPS Number.\n"
		
    } else {
        fld.style.borderColor = '#999999' ;
    }
    return error;  
}
function validateSamplesValidation(fld) {
    var error = "";
    if (fld.value.length == 0) {
        fld.style.borderColor = "#FF0000";
		error = "You must enter the Validation Code displayed on the left.\n"
		
    } else {
        fld.style.borderColor = '#999999' ;
    }
    return error;  
}
function validateLName(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.borderColor = "#FF0000";
		error = "You must enter your Last Name.\n"
		
    } else {
        fld.style.borderColor = '#999999' ;
    }
    return error;  
}
function validateFullName(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FFFFD2'; 
        error = "You didn't enter a name.\n"
		
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function checkfrm_callback(theForm) {
var reason = "";
  reason += validateEmpty(theForm.txtProdName);
  reason += validateEmpty(theForm.txtFullName);
  reason += validateEmpty(theForm.txtCompanyName);
  reason += validateEmail(theForm.txtEmail);
  reason += validatePhone(theForm.txtPhone);
 
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}
function checkfrm_money(theForm) {
var reason = "";
  reason += validateEmpty(theForm.txtFullName);
  reason += validateEmpty(theForm.txtCompanyName);
  reason += validateEmail(theForm.txtEmail);
  reason += validatePhone(theForm.txtPhone);
 
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}
function checkfrm_services(theForm) {
var reason = "";
  reason += validateEmpty(theForm.txtProdName);
  reason += validateUpload(theForm.uploadedfile1, theForm.uploadedfile2, theForm.uploadedfile3, theForm.uploadedfile4 );
  reason += validateEmpty(theForm.txtFullName);
  reason += validateEmpty(theForm.txtCompanyName);
  reason += validateEmail(theForm.txtEmail);
  reason += validatePhone(theForm.txtPhone);

  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validateUpload(fld1, fld2, fld3, fld4) {
    var error = "";
 
    if (fld1.value.length == 0 && fld2.value.length == 0 && fld3.value.length == 0 && fld4.value.length == 0) {
        fld1.style.background = '#FFFFD2'; 
        error = "Please upload your logo.\n"
		
    } else {
        fld1.style.background = 'White';
    }
    return error;  
}
function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FFFFD2'; 
        error = "The required field has not been filled in.\n"
		
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = '#FFFFD2'; 
        error = "You didn't enter a username.\n";
		
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        fld.style.background = '#FFFFD2'; 
        error = "The username is the wrong length.\n";
		
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#FFFFD2'; 
        error = "The username contains illegal characters.\n";
		
    } else {
        fld.style.background = 'White';
    }
    return error;
}

/*
function trim(s) {
	// Remove leading spaces and carriage returns
	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
	 { s = s.substring(1,s.length); }
	 
	// Remove trailing spaces and carriage returns
	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
	 { s = s.substring(0,s.length-1); }
	 
	return s;
}
   
*/
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
  return s;
}


function validateNewEmail(fld) {
	var error="";
    var tfld = trim(fld.value);    
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#FFFFD2'; 
        error = "You must enter an email address.\n";
		
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#FFFFD2'; 
        error = "Please enter a valid email address.\n";
		
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#FFFFD2'; 
        error = "The email address contains illegal characters.\n";
		
    } else {
        fld.style.background = 'White'; 
    }
	return error;
}
function validateEmail(fld) {
    var error="";
	/*
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.borderColor = '#FF0000'; 
        error = "You must enter an email address.\n";
		
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.borderColor = '#FF0000';
        error = "Please enter a valid email address.\n";
		
    } else if (fld.value.match(illegalChars)) {
        fld.style.borderColor = '#FF0000';
        error = "The email address contains illegal characters.\n";
		
    } else {
        fld.style.borderColor = '#000000';
    }
	*/
    return error;
}

function validatePhoneSamples(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You must enter your Phone Number.\n";
		fld.style.borderColor = "#FF0000";
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
		fld.style.borderColor = "#FF0000";
    } else {
        fld.style.borderColor = '#999999' ;
    }
    return error;
}
	
function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter a phone number.\n";
        fld.style.background = '#FFFFD2';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
		
        fld.style.background = '#FFFFD2';
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateNumber(fld) {
    var error = "";
	if (fld.value.length == 0) {
        fld.style.background = '#FFFFD2'; 
        error = "The required field has not been filled in.\n"
		
    } 
    else if (isNaN(fld.value))
	{
	 	error = "You didn't enter your quantity as a number.\n";
		
        fld.style.background = '#FFFFD2';
	}
	else
	{
		fld.style.background = 'White';
	}
    return error;
}

function ShowImage(file,wd,ht)
{
	       
	  if(wd==null) { wd = 300;}
	  if(ht==null) { ht = 400;}
	  var left = Math.floor( (screen.width - wd) / 2);
      var top = Math.floor( (screen.height - ht) / 2);
	  //prop="status=no,toolbar=no,menubar=no,top=2,left=2,width="+wd+",height="+ht;
	  prop= "top=" + top + ",left=" + left + ",height=" + ht + ",width=" + wd;
	  newWin=window.open(file,"ShowImage",prop);
	  newWin.focus();
}
function ShowProduct(sProductCode,wd,ht)
{
	  if(wd==null) { wd = 300;}
	  if(ht==null) { ht = 400;}
	  var left = Math.floor( (screen.width - wd) / 2);
      var top = Math.floor( (screen.height - ht) / 2);
	  prop= "top=" + top + ",left=" + left + ",height=" + ht + ",width=" + wd;
	  newWin=window.open("product.php?productCode="+sProductCode,"ShowImage",prop);
	  newWin.focus();
}
