function validateFSearch(theform){
		if(theform.column.selectedIndex==0) {
			alert('Please select what you want to search for')
			theform.column.focus()
			return false
		}


	return true	
}

function validateFSearch2(theform){
		if(theform.category.selectedIndex==0) {
			alert('Please select the category first')
			theform.category.focus()
			return false
		}

		if(theform.column.selectedIndex==0) {
			alert('Please select what you want to search for')
			theform.column.focus()
			return false
		}


	return true	
}

function validateGiftpack(theform){
		var selection = theform.gift_gc
		var sel=false
		
		if(selection.length==0){
			  if (selection.checked==true) {
					sel=true
			  }
		}else{
			for (i=0;i<selection.length;i++){
				  if (selection[i].checked==true) {
						sel=true
				  }
			}
		}
			  
		if (sel==false) {
			alert("Please select a card from our collection");
			//theform.gift_gc[0].focus()
			return false
		}
	
		if(theform.gc_msg.value=='') {
			alert('Please enter your greeting messages in the message box')
			theform.gc_msg.focus()
			return false
		}


	return true	
}

function validatePurchase(theform, checkAddress)
{
  if (checkAddress == undefined) {
    checkAddress = true;
  }
  if (checkAddress) {
		if(theform.saddress[0].checked==false && theform.saddress[1].checked==false) {
			document.getElementById('delivery-address-table').style.border = '1px solid red';
            alert('Please select your address')
			theform.agree.checked=false
			theform.saddress[0].focus();            
			return false
		}
        document.getElementById('delivery-address-table').style.border = '';
  }
    if (theform.coupon_email != undefined) {
      if (!emailValidator(theform.coupon_email)) {
        alert('Please enter valid recipient email');
        theform.coupon_email.focus();
        return false;
      }
    }

   if (checkAddress) {
		if(theform.saddress[0].checked==true) {
			if(theform.name.value=='') {
				theform.agree.checked=false
				alert('Please enter your Name')
				theform.name.focus()
				return false
			}
		
			if(theform.family_name.value=='') {
				theform.agree.checked=false
				alert('Please enter your Family Name')
				theform.family_name.focus()
				return false
			}
		
			if(theform.address.value=='') {
				theform.agree.checked=false
				alert('Please enter your Address')
				theform.address.focus()
				return false
			}
		
			if(theform.zip.value=='') {
				theform.agree.checked=false
				alert('Please enter your Zip code')
				theform.zip.focus()
				return false
			}
		
			if(theform.city.value=='') {
				theform.agree.checked=false
				alert('Please enter your City')
				theform.city.focus()
				return false
			}
		
			if(theform.country.selectedIndex=='0') {
				theform.agree.checked=false
				alert('Please enter your Country')
				theform.country.focus()
				return false
			}
		
			if(theform.phone.value=='') {
				theform.agree.checked=false
				alert('Please enter your Telephone number')
				theform.phone.focus()
				return false
			}
		
			if(theform.country_code.value=='') {
				theform.agree.checked=false
				alert('Please enter your Country Code')
				theform.country_code.focus()
				return false
			}

			if(theform.email.value=='') {
				theform.agree.checked=false
				alert('Please enter your Email address')
				theform.email.focus()
				return false
			}

			if(theform.email.value!='') {
				if(emailValidator(theform.email)==false) {
					theform.agree.checked=false
					alert('The Email address is not valid. Please enter a valid Email address')
					theform.email.focus()
					return false
				}
			}

		}else if(theform.saddress[1].checked==true){
			
			if(theform.name2.value=='') {
				theform.agree.checked=false
				alert('Please enter your Name')
				theform.name2.focus()
				return false
			}
		
			if(theform.family_name2.value=='') {
				theform.agree.checked=false
				alert('Please enter your Family Name')
				theform.family_name2.focus()
				return false
			}
		
			if(theform.address2.value=='') {
				theform.agree.checked=false
				alert('Please enter your Address')
				theform.address2.focus()
				return false
			}
		
			if(theform.zip2.value=='') {
				theform.agree.checked=false
				alert('Please enter your Zip code')
				theform.zip2.focus()
				return false
			}
		
			if(theform.city2.value=='') {
				theform.agree.checked=false
				alert('Please enter your City')
				theform.city2.focus()
				return false
			}
		
			if(theform.country2.selectedIndex=='0') {
				theform.agree.checked=false
				alert('Please enter your Country')
				theform.country2.focus()
				return false
			}
		
			if(theform.phone2.value=='') {
				theform.agree.checked=false
				alert('Please enter your Telephone number')
				theform.phone2.focus()
				return false
			}
		
			if(theform.country_code2.value=='') {
				theform.agree.checked=false
				alert('Please enter your Country Code')
				theform.country_code2.focus()
				return false
			}

			if(theform.email2.value=='') {
				theform.agree.checked=false
				alert('Please enter your Email address')
				theform.email2.focus()
				return false
			}

			if(theform.email2.value!='') {
				if(emailValidator(theform.email2)==false) {
					theform.agree.checked=false
					alert('The Email address is not valid. Please enter a valid Email address')
					theform.email2.focus()
					return false
				}
			}
		}
   }
	document.getElementById('make_pay').disabled = false;
	return true;
}


function validateRegister(theform){
			if(theform.name.value=='') {
				alert('Please enter your Name')
				theform.name.focus()
				reloadRecaptcha();
				return false
			}
		
			if(theform.family_name.value=='') {
				alert('Please enter your Family Name')
				theform.family_name.focus()
				reloadRecaptcha();
				return false
			}
		
			if(theform.password.value=='') {
				alert('Please enter your password')
				theform.password.focus()
				reloadRecaptcha();
				return false
			}

			if(theform.password.value!=''||theform.password2.value!='') {
				if(theform.password.value!=theform.password2.value) {
					alert('Your passwords do not match.\nPlease re-enter them again')
					theform.password.focus()
					reloadRecaptcha();
					theform.password.value=''
					theform.password2.value=''
					return false
				}
			}
			
			if(theform.email.value=='') {
				alert('Please enter your Email address')
				theform.email.focus()
				reloadRecaptcha();
				return false
			}

			if(theform.email.value!=''||theform.email2.value!='') {
				if(theform.email.value!=theform.email2.value){
					alert('Your email address do not match.\nPlease re-enter again')
					theform.email2.focus()
					reloadRecaptcha();
					//theform.email.value=''
					theform.email2.value=''
					return false
				}
			}


			if(theform.email.value!='') {
				if(emailValidator(theform.email)==false) {
					alert('The Email address is not valid. Please enter a valid Email address')
					theform.email.focus()
					reloadRecaptcha();
					return false
				}
			}

			if(theform.email_chk.value=='1') {
				alert('Please use a different email address')
				theform.email.focus()
				reloadRecaptcha();
				return false
			}

			if(theform.country_code.value=='') {
				alert('Please enter your Country Code')
				theform.country_code.focus()
				reloadRecaptcha();
				return false
			}

			if(theform.phone.value=='') {
				alert('Please enter your Telephone number')
				theform.phone.focus()
				reloadRecaptcha();
				return false
			}
		
			if(theform.address.value=='') {
				alert('Please enter your Address')
				theform.address.focus()
				reloadRecaptcha();
				return false
			}
		
			if(theform.zip.value=='') {
				alert('Please enter your Zip code')
				theform.zip.focus()
				reloadRecaptcha();
				return false
			}
		
			if(theform.city.value=='') {
				alert('Please enter your City')
				theform.city.focus()
				reloadRecaptcha();
				return false
			}
		
			if(theform.recaptcha_response_field.value=='') {
				alert('Please the security code!')
				theform.code.focus()
				reloadRecaptcha();
				return false
			}
		
			if(theform.country.selectedIndex=='0') {
				alert('Please enter your Country')
				theform.country.focus()
				reloadRecaptcha();
				return false
			}
				
    alert("Thank you for creating an account on Pix2Paint - you will receive a confirmation via email.");
	return true
}

function reloadRecaptcha() {
  Recaptcha.reload();
  $j('#recaptcha_response_field').val();
}


function validateAffiliate(theform){
			if(theform.name.value=='') {
				alert('Please enter your Name')
				theform.name.focus()
				return false
			}
		
		
			if(theform.password.value=='') {
				alert('Please enter your Password')
				theform.password.focus()
				return false
			}
		
			if(theform.email.value=='') {
				alert('Please enter your Email address')
				theform.email.focus()
				return false
			}

			if(theform.email.value!='') {
				if(emailValidator(theform.email)==false) {
					alert('The Email address is not valid. Please enter a valid Email address')
					theform.email.focus()
					return false
				}
			}

			if(theform.email_chk.value=='1') {
				alert('Please use a different email address')
				theform.email.focus()
				return false
			}


			if(theform.contact.value=='') {
				alert('Please enter your Contact number')
				theform.contact.focus()
				return false
			}
		

	return true
}


function ValidatePostcard1(theform){

		if(theform.pic_opt.value=='pic_upload') {
			
			if(theform.image.value.length==0) {
				alert('Please select a file to upload')
				theform.image.focus()
				return false
			}

      var ver = document.getElementById('orientation_t1');
      var hor = document.getElementById('orientation_t2');
      if (!ver.checked && !hor.checked) {
        alert('Please select Orientation of your postcard.');
        ver.focus();
        return false;
      }

			intDot = theform.image.value.indexOf(".")
			intDifference = theform.image.length - intDot
			if(intDifference>4){
				alert("Please enter a valid file name");
				theform.image.focus()
				return false
			}

			if(theform.style.selectedIndex == 0 ) {
				alert('Please select the Painting Style.')
				theform.style.focus()
				return false
			}
		
			if(theform.type.selectedIndex == 0 ) {
				alert('Please select the Type of Painting you prefer.')
				theform.type.focus()
				return false
			}
		

			
		}else if(theform.pic_opt.value=='stock') {

			var selection = theform.custom_gc
			var sel=false
			for (i=0;i<selection.length;i++){
				  if (selection[i].checked==true) {
				  		sel=true
				  }
			}
				  
			if (sel==false) {
				alert("Please select a card from our collection");
				theform.custom_gc[0].focus()
				return false
			}
			
		}else if(theform.pic_opt.value=='ext') {

			if(theform.ext_img==null){
				alert("Please search for a photo first");
				return false	
			}else{
			
				var selection = theform.ext_img
				var sel=false
				for (i=0;i<selection.length;i++){
					  if (selection[i].checked==true) {
							sel=true
					  }
				}
					  
				if (sel==false) {
					alert("Please select a photo to use first");
					theform.ext_img[0].focus()
					return false
				}
	
				if(theform.style.selectedIndex == 0 ) {
					alert('Please select the Painting Style.')
					theform.style.focus()
					return false
				}
			
				if(theform.type.selectedIndex == 0 ) {
					alert('Please select the Type of Painting you prefer.')
					theform.type.focus()
					return false
				}
			}
		}	

	theform.checkL.value='1';
	
	checkLoad();

	return true
	
}

function ValidateCustompaint(theform)
{
    if(theform.pic_opt.value=='pic_upload') {
        if(theform.image.value.length==0) {
            alert('Please select a file to upload')
            theform.image.focus()
            return false
        }

        intDot = theform.image.value.indexOf(".")
        intDifference = theform.image.length - intDot
        if(intDifference>4){
            alert("Please enter a valid file name");
            theform.image.focus()
            return false
        }

				
    } else if(theform.pic_opt.value == 'ext') {

        if(theform.ext_img==null){
            alert("Please search for a photo first");
            return false
        }else{
			
            var selection = theform.ext_img
            var sel=false
            for (i=0;i<selection.length;i++){
                if (selection[i].checked==true) {
                    sel=true
                }
            }
					  
            if (sel==false) {
                alert("Please select a photo to use first");
                theform.ext_img[0].focus()
                return false
            }
        }
    }
		 
		 
    if (theform.style.selectedIndex == 0 ) {
        alert ( "Please select the Painting Style." )
        theform.style.focus()
        return false
    }
	
    if (theform.type.selectedIndex == 0 ) {
        alert ( "Please select the Type of Painting you prefer." )
        theform.type.focus()
        return false
    }
	
    if (theform.type.selectedIndex == 1 ) {
        if (theform.portrait_option.selectedIndex == 0 ) {
            alert ( "Please select the options for this Type of Painting." )
            theform.portrait_option.focus()
            return false
        }
    }

    if (theform.type.value == 'Reproductions' ) {
        if (theform.repo_option.selectedIndex == 0 ) {
            alert ( "Please select the options for this Type of Painting." )
            theform.repo_option.focus();
            return false;
        }
    }

    /* var notSelected = true;
    var sizeNumber = 0;
    var firstSize = document.getElementById('size3');
    
    if(firstSize.style.display != 'none') {
        sizeNumber = 0;
        if (firstSize.value != '0') {
            notSelected = false;
        }
    } else {
        sizeNumber = 1;
        var secondSize = document.getElementById('size2');
        if (secondSize.value != '0') {
            notSelected = false;
        }
    }
    if (notSelected) {
        alert ( "Please select the Painting Size." )
        theform.size[sizeNumber].focus();
        return false;
    } */

    if (theform.orientation[0].checked == false && theform.orientation[1].checked == false ) {
        alert ( "Please select the Orientation of your Painting." );
        theform.orientation[0].focus();
        return false;
    }

    theform.checkL.value='1';
    checkLoad();
	
    return true;
}

function ValidateCustompaint2(theform, type) {
  if (undefined == type) {
    type = 'custom';
  }
  if (type == 'repo') {    
    if (theform.radio.value == '0') {
      alert('Please select a your Framing option.')
      return false
    }else if(theform.radio.value == 'frame'){

      var selection = theform.frames
      var sel=false
      for (i=0;i<selection.length;i++){
          if (selection[i].checked==true) {
            sel=true
          }
      }

      if (sel==false) {
        alert("Please selct a frame for your painting.");
        theform.frames[0].focus()
        return false
      }

    }
    return true;
  }

	if(theform.frame_opt.value=='0'){
		alert('Please select a your Framing option.')
		return false
	}else if(theform.frame_opt.value=='frame'){
	
		var selection = theform.frames
		var sel=false
		for (i=0;i<selection.length;i++){
			  if (selection[i].checked==true) {
					sel=true
			  }
		}
			  
		if (sel==false) {
			alert("Please selct a frame for your painting.");
			theform.frames[0].focus()
			return false
		}
	
	}
	return true
}


function validatePostcard(theform){
		if(theform.style.selectedIndex == 0 ) {
			alert('Please select the Painting Style.')
			theform.style.focus()
			return false
		}
    
	
		if(theform.type.selectedIndex == 0 ) {
			alert('Please select the Type of Painting you prefer.')
			theform.type.focus()
			return false
		}
	return true
	
}

function validateReorder(theform){
		if(theform.option[0].checked==false && theform.option[1].checked==false) {
			alert('Please select an option before re-order')
			theform.option[0].focus()
			return false
			
		}	
	return true
}

function ValidateUser(theform){
	
			if(theform.name.value=='') {
				alert('Please enter your Name')
				theform.name.focus()
				return false
			}
		
			if(theform.family_name.value=='') {
				alert('Please enter your Family Name')
				theform.family_name.focus()
				return false
			}
		
			if(theform.password1.value!=''||theform.password2.value!='') {
				if(theform.password1.value!=theform.password2.value) {
					alert('Your passwords do not match.\nPlease re-enter them again')
					theform.password1.focus()
					theform.password1.value=''
					theform.password2.value=''
					return false
				}
			}

			if(theform.address.value=='') {
				alert('Please enter your Address')
				theform.address.focus()
				return false
			}

			if(theform.zip.value=='') {
				alert('Please enter your Zip code')
				theform.zip.focus()
				return false
			}
		
			if(theform.city.value=='') {
				alert('Please enter your City')
				theform.city.focus()
				return false
			}
		
			if(theform.country.selectedIndex=='0') {
				alert('Please enter your Country')
				theform.country.focus()
				return false
			}
		
			if(theform.country_code.value=='') {
				alert('Please enter your Country Code')
				theform.country_code.focus()
				return false
			}

			if(theform.phone.value=='') {
				alert('Please enter your Telephone number')
				theform.phone.focus()
				return false
			}
		
			if(theform.email.value=='') {
				alert('Please enter your Email address')
				theform.email.focus()
				return false
			}

			if(theform.email.value!='') {
				if(emailValidator(theform.email)==false) {
					alert('The Email address is not valid. Please enter a valid Email address')
					theform.email.focus()
					return false
				}
			}

	return true
}


function ValidateAffReg(theform){
	
			if(theform.company.value=='') {
				alert('Please your company name')
				theform.company.focus()
				return false
			}
		
			if(theform.name.value=='') {
				alert('Please enter your name')
				theform.name.focus()
				return false
			}
		
			if(theform.country.selectedIndex=='0') {
				alert('Please enter your Country')
				theform.country.focus()
				return false
			}
		
			if(theform.email.value=='') {
				alert('Please enter your Email address')
				theform.email.focus()
				return false
			}            

			if(theform.email.value!='') {
				if(emailValidator(theform.email)==false) {
					alert('The Email address is not valid. Please enter a valid Email address')
					theform.email.focus()
					return false
				}
			}

			if(theform.email_chk.value=='1') {
				alert('Please use a different email address')
				theform.email.focus()
				return false
			}

            if(theform.tel.value=='') {
				alert('Please enter your Telephone number')
				theform.tel.focus()
				return false
			}
		
			if(theform.code.value=='') {
				alert('Please enter the security code!')
				theform.code.focus()
				return false
			}
            
			if(theform.codeval.value=='0') {
				theform.code.focus()
				return false
			}
            
	return true;
}


function ValidateForm(theform)
{
		if(theform.name.value=='') {
		alert('Please enter your Name')
		theform.name.focus()
		return false
	}

		if(theform.email.value=='') {
		alert('Please enter your Email address')
		theform.email.focus()
		return false
	}

		if(theform.email.value!='') {
			if(emailValidator(theform.email)==false) {
			alert('The Email address is not valid. Please enter a valid Email address')
			theform.email.focus()
			return false
		}
	}

		if(theform.email_chk.value=='1') {
		alert('Please use a different email address')
		theform.email.focus()
		return false
	}

		if(theform.phone.value=='') {
		alert('Please enter your Contact Number')
		theform.phone.focus()
		return false
	}
	
		if(theform.address.value=='') {
		alert('Please enter your Address')
		theform.address.focus()
		return false
	}
	
		if(theform.zip.value=='') {
		alert('Please enter your Zip Code')
		theform.zip.focus()
		return false
	}
	
		if(theform.country.value=='') {
		alert('Please enter your country')
		theform.country.focus()
		return false
	}
	
	return true
}


function ValidateForm1(theform)
{
		if(theform.name.value=='' && theform.email.value=='' && theform.discount_code.value=='') {
		alert('Please enter your Name or Email Address or Discount Code')
		theform.email.focus()
		return false
	}
	return true
}

function ValidateForm2(theform)
{
		if(theform.name.value=='') {
		alert('Please enter your Name')
		theform.name.focus()
		return false
	}

		if(theform.address.value=='') {
		alert('Please enter your Address')
		theform.address.focus()
		return false
	}

		if(theform.email.value=='') {
		alert('Please enter your Email address')
		theform.email.focus()
		return false
	}

		if(theform.email.value!='') {
			if(emailValidator(theform.email)==false) {
			alert('The Email address is not valid. Please enter a valid Email address')
			theform.email.focus()
			return false
		}
			if(theform.email_chk.value=='1') {
			alert('Please use a different email address')
			theform.email.focus()
			return false
		}

	}
	
		if(theform.discount_chk.value!='') {
			if(theform.discount_chk.value=='1') {
			alert('Invalid discount code')
			theform.discount_code.focus()
			return false
		}
	}
		
		if(theform.contact_num.value=='') {
		alert('Please enter your Contact Number')
		theform.contact_num.focus()
		return false
	}

	return true
}

function ValidateForm3(theform)
{
		if(theform.attnto.value=='') {
		alert('Please enter person\'s name receiving goods.')
		theform.attnto.focus()
		return false
	}

		if(theform.ship_address.value=='') {
		alert('Please enter the shipping address')
		theform.ship_address.focus()
		return false
	}

		if(theform.contact_num.value=='') {
		alert('Please enter the Contact Number')
		theform.contact_num.focus()
		return false
	}
	return true
}


function Validateorder(theform)
{
	var form=document.forms['theform'];
	var length=form.length;
	for (var i=0; i<length; i++)
 	{
    	if (form.elements[i])
    	{
			//Check object here...
			if (form.elements[i].selectedIndex == '0')
			{
			//	form.elements[i].selectedIndex == '1'
			//	var opt = explode('::', form.elements[i].select.value);
			//	var opt_type = opt[0];
			//	var type_val = opt[1];
				alert('You must '+form.elements[i].value);
				form.elements[i].focus()
				return false
			}
    	}
 	}
	return true
}

function ValidateSpread(theform)
{
		if(theform.name.value=='') {
		alert('Please enter your Name')
		theform.name.focus()
		return false
	}

		if(theform.email.value=='') {
		alert('Please enter your Email address')
		theform.email.focus()
		return false
	}

		if(theform.email.value!='') {
			if(emailValidator(theform.email)==false) {
			alert('The Email address is not valid. Please enter a valid Email address')
			theform.email.focus()
			return false
		}
	}
	
		if(theform.email_to.value=='') {
		alert('Please enter the email address of your friends')
		theform.email_to.focus()
		return false
	}
	return true
}


function emailValidator(elem){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,10}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		return false;
	}
}

function explode( delimiter, string, limit ) {
    // http://kevin.vanzonneveld.net
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
 
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}
