function CheckEmail (Ema) {
		
	email = Ema.value.toString();
	
	t = email.indexOf("@");
	
	if((email.indexOf(".") == -1) || (t == -1) || (t < 1) || (t > email.length - 5) || (email.charAt(t - 1) == '.') || (email.charAt(t + 1) == '.')) {
			
			alert("Please, Check Your E-mail");
			Ema.focus();
			
		return false;
		} 

}

	// check telephone
function CheckTelephone (Tel)	 {

	var checktel="0123456789 -+()";
	
	for(i=0; i < Tel.value.length; i++) {
			if (checktel.indexOf(Tel.value.charAt(i))<0)  {
				
				alert("Please, Check Telephone. It Must be Digits or ()-+")
				Tel.focus();
				return false;
			}
	}
}



function isEmpty(str) {
   for (var i = 0; i < str.length; i++)
      if (" " != str.charAt(i))
          return false;
      return true;
}

function CheckForm(f) {



  var errMSG = "";             
  for (var i = 0; i<f.elements.length; i++) 

    if (null!=f.elements[i].getAttribute("required")) 
        if (isEmpty(f.elements[i].value)) 
            errMSG += "  " + f.elements[i].name + "\n"; 
                                                       
                                                         
        if ("" != errMSG) {
            alert("Required Fields are not Filled:\n" + errMSG);
            return false;
        }
		
		
	email = f.email.value.toString();
			t = email.indexOf("@");
		if((email.indexOf(".") == -1) || (t == -1) || (t < 1) || (t > email.length - 5) || (email.charAt(t - 1) == '.') || (email.charAt(t + 1) == '.')) {
			
			alert ('Please, Check E-mail');
			f.email.focus();
			
		return false;
		}  
	
}

function DeleteProduct (Id) {

	if (confirm ('You Will Delete Item')){
		
		document.DeleteP.DeleteId.value = Id;
		document.DeleteP.submit();
		
		return false;
	} else {
		
		return false;
		}
	
}

function CheckContactForm (f) {

	if (f.name.value.length < 1 ){
		alert("Sorry, Name is Mandatory Field");
		f.name.focus();
		return false;
	}
	
	if (f.email.value.length < 1 ){
		alert("Sorry, E-mail is Mandatory Field");
		f.email.focus();
		return false;
	}
	
	if (f.telephone.value.length < 1 ){
		alert("Sorry, Telephone is Mandatory Field");
		f.telephone.focus();
		return false;
	}
	

		

	if (CheckEmail (f.email) === false) {
		
		return false;
		
	}
	
	if (CheckTelephone (f.telephone) === false) {
		
		return false;
		
	}
	
	
}

function CheckDistributorsForm (f) {
	
		if (f.name.value.length < 1 ){
		alert("Sorry, Name is Mandatory Field");
		f.name.focus();
		return false;
	}
	
	if (f.company.value.length < 1 ){
		alert("Sorry, Company is Mandatory Field");
		f.company.focus();
		return false;
	}
	
	if (f.address.value.length < 1 ){
		alert("Sorry, Address is Mandatory Field");
		f.address.focus();
		return false;
	}
	
	if (f.telephone.value.length < 1 ){
		alert("Sorry, Telephone is Mandatory Field");
		f.telephone.focus();
		return false;
	}
	
	
	if (f.email.value.length < 1 ){
		alert("Sorry, E-mail is Mandatory Field");
		f.email.focus();
		return false;
	}
	
	if (CheckEmail (f.email) === false) {
		
		return false;
		
	}
	
	if (f.comments.value.length < 1 ){
		alert("Sorry, Comments is Mandatory Field");
		f.comments.focus();
		return false;
	}
	

	if (CheckTelephone (f.telephone) === false) {
		
		return false;
		
	}
	
	
	
}


function CheckGiftVoucherForm (f) {

	if (f.Card_Message.value.length < 1 ){
		alert("Sorry, Card Message is Mandatory Field");
		f.Card_Message.focus();
		return false;
	}

	if (f.Name_of_Recipient.value.length < 1 ){
		alert("Sorry, Name of Recipient is Mandatory Field");
		f.Name_of_Recipient.focus();
		return false;
	}

	if (f.Name_of_Sender.value.length < 1 ){
		alert("Sorry, Name of Sender is Mandatory Field");
		f.Name_of_Sender.focus();
		return false;
	}

	if (f.Address_of_Recipient.value.length < 1 ){
		alert("Sorry, Address of Recipient is Mandatory Field");
		f.Address_of_Recipient.focus();
		return false;
	}

	if (f.Post_Code.value.length < 1 ){
		alert("Sorry, Post Code is Mandatory Field");
		f.Post_Code.focus();
		return false;
	}

	
}

function CheckTellaFriendForm (f) {

	if (f.your_name.value.length < 1 ){
		alert("Sorry, your name is Mandatory Field");
		f.your_name.focus();
		return false;
	}

	if (f.your_email_address.value.length < 1 ){
		alert("Sorry, your e-mail address is Mandatory Field");
		f.your_email_address.focus();
		return false;
	}
	
	if (CheckEmail (f.your_email_address) === false) {
		
		return false;
		
	}	
	
	if (f.friends_name.value.length < 1 ){
		alert("Sorry, friends name  is Mandatory Field");
		f.friends_name.focus();
		return false;
	}
	
	if (f.friends_email_address.value.length < 1 ){
		alert("Sorry, friends e-mail address is Mandatory Field");
		f.friends_email_address.focus();
		return false;
	}
	
	if (CheckEmail (f.friends_email_address) === false) {
		
		return false;
		
	}
	
	if (f.message.value.length < 1 ){
		alert("Sorry, A personal message is Mandatory Field");
		f.message.focus();
		return false;
	}

	

}

function KnitverSizeSelect(id1, id2) {


 if (document.getElementById && document.getElementsByTagName) {


  var sel1 = document.getElementById(id1);
  var sel2 = document.getElementById(id2);
	
  sel2.disabled  = false;

  var clone = sel2.cloneNode(true);

  var clonedOptions = clone.getElementsByTagName("option");

  refreshDynamicSelectOptions(sel1, sel2, clonedOptions);

  sel1.onchange = function() {
  refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
  }
 }
}

function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) {

 while (sel2.options.length) {
  sel2.remove(0);
 }
 var pattern1 = /( |^)(select)( |$)/;
 var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");

 for (var i = 0; i < clonedOptions.length; i++) {

  if (clonedOptions[i].className.match(pattern1) ||
  clonedOptions[i].className.match(pattern2)) {


   sel2.appendChild(clonedOptions[i].cloneNode(true));
  }
 }
}

