function NewThumbNail()
         {
		 var File;
		 var Image1;
		 File = document.addProduct.photo;
		 Image1 = document.addProduct.image1;
		// alert(Image1.src);
		 if(File.value != '')
		   {		   
		   Image1.src = File.value;
		   }
		 }	 
function validate(num) {
	 if ((num==1) & (document.addProduct.photo.value!=""))
	 		{
				if (!alertPhoto())
					return false;
			}
				if (!valid2())
					return false;
					//alert("here");
	return true;
}

function valid2()
{
	   maxlength=100;
	 if(document.addProduct.product_description.value.length>=maxlength) {
          alert('The product description must be '+maxlength+' characters or less');
          document.addProduct.product_description.focus();
          return false;
     } else {
           if (!checkForm2(2))
			return false;	
     }
	 return true;
}

function getfilename(filepath)
{
	name = filepath;
	value1=name.split("\\");
	name=value1[value1.length-1].substring(0,name.length-4);
	//alert(name);
	return name;
}

function selectall()
{
	form=document.form1;
	if (form.button1.value=="Select All")
	{	
		form.button1.value="Deselect All";
		  check=true;
	}
	else if (form.button1.value=="Deselect All")
	{
		form.button1.value="Select All";
		   check=false;	
	}
  with (form) {
    for (var i=0; i < elements.length; i++) {
        if (elements[i].type == 'checkbox' )
		{
           elements[i].checked = check;
		  
		}
    }
  }
}

function confirmSubmit()
{
	if (checkForm())
	{
		if ( confirm1())
		return true;
		else
		return false;}	
	return false;
}

function confirm1()
{
		var agree=confirm("Are you sure you delete?");
		if (agree)
			return true ;
		else
			return false ;
}
function checkForm()
{
  with (document.form1) {
    for (var i=0; i < elements.length; i++) {
        if (elements[i].type == 'checkbox')
           if (elements[i].checked == true)
		   return true;
    }
  }
  alert("Please choose");
  return false;
}

function showPic (whichpic,here,width1,height1) {
 if (document.getElementById) {
	  document.SHOWPAD.height = height1;
	  //alert(photo1.height);
	  document.SHOWPAD.width = width1; 	
	  document.getElementById("placeholder").src = whichpic;
	  array=here.name.split("|&^");
	 document.getElementById('name').childNodes[0].nodeValue = array[0];
	 document.getElementById('desc').childNodes[0].nodeValue = array[1];
 	return false;
 } else {
  return true;
 }
}

function checkEmpty(formstr)
{
	if (formstr.value=="")
	{
		alert("Please enter "+formstr.name.replace("_"," "));
		formstr.focus();
		return true;
	}
	return false;
}

function checkForm2(id)
{
	form=document.addProduct;
	if (id==1)
	{
		if (checkEmpty(form.name))
			return false;
	}
	else if (id==2)
	{
		if (checkEmpty(form.code))
			return false;
	}
	if (getfilename(document.addProduct.photo.value).indexOf("#") != -1 || getfilename(document.addProduct.photo.value).indexOf("%") != -1)
	{
		alert("the file name cannot contain '#','%' ") 
		return false
	}
	if (!alertPhoto())
		return false;
	fmtHTMLChar(form);
	return true;
}

function fmtHTMLChar(form) {
	var len = form.elements.length
	for (var i = 0; i<len; i++) {
		var thisform = form.elements[i]
		if (thisform.type!="file"){
				//alert(thisform.type);
		while (thisform.value.indexOf("'") != -1 ||
				thisform.value.indexOf("<") != -1 ||
				thisform.value.indexOf(">") != -1 ||
				thisform.value.indexOf("%") != -1) {
			
			thisform.value = thisform.value.replace("'", "&#39;").replace("%", "&#37;").replace("<", "&lt;").replace(">", "&gt;")
			}
		}
	}
}

function unFmtHTMLChar() {
	var formCnt = document.forms.length
	for (var i = 0; i<formCnt; i++) {
		var len = document.forms[i].elements.length
		for (var j = 0; j<len; j++) {
			var form = document.forms[i].elements[j]
			while (form.value.indexOf("&#39;") != -1 ||
					form.value.indexOf("&lt;") != -1 ||
					form.value.indexOf("&gt;") != -1 ||
					form.value.indexOf("&#37;") != -1) {
				form.value = form.value.replace("&#39;", "'").replace("&#37;", "%").replace("&lt;", "<").replace("&gt;", ">")
			}
		}
	}
}

function alertPhoto()
{
	form=document.addProduct;
	//alert(form.value.value==0);
	if (form.value.value!="" && form.value.value!=0)
	{
		if (form.photo.value!="" && form.photoName.value!="")
		 if (confirm ("Please remind that the old photo will be deleted "))
			 return true;
		 else
			return false;
	}else if (form.action.value=="product")
	{		
		if (form.actiontype.value=="add" && form.photo.value=='')
		{
			alert("Please insert a photo");
			return false;
		}else
			return true;
	}
	return true;
}

function alertsubcat()
{
	 if (confirm ("Please remind that all the products will be deleted in the subcategory "))
	 return true;
	 else
	 return false;
}
function showImg(pic,num)
{
	//alert(pic);
	document.getElementById('cspbBtn'+num).style.display='none';
	pic.style.visibility='visible';
}

function ISOpopup()
{
	window.open('ISO.html', 'bgcaAdmin', 'width=600, height=850, resizable=yes, scrollbars=yes');
}

function ShowPicture (photo,num)
{	 
	 document.SHOWPAD.height = eval("photo"+num).height;
	 document.SHOWPAD.width = eval("photo"+num).width; 	
	 document.SHOWPAD.src = eval("photo"+num).src;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
 	   eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) selObj.selectedIndex=0;
}

function isEmail(email)
{
	var emailPattern = /^\w+[\w\.-]+@[\w\.-]+\.\w+$/g
	if (emailPattern.test(email.value)) 
	return true;	
	alert("Please enter valid email ");
	select(email)
	return false;
}

function isEmpty(inputStr) {
	if (isNaN(inputStr) || inputStr=="") {
		return true
	}
	return false
}

function isEmptyInForm(formStr,value) {
	//alert(formStr.name);
	if ((formStr.type=="text") || (formStr.type=="password") || (formStr.type=="select-one") || (formStr.type=="textarea") )
	{
	if (formStr.value == "" || formStr.value == null) {
	alert("Please enter "+value);
	select(formStr);
		return true
		}
	}
	else if (formStr[0].type=="radio")
	{
	//alert("here");
	Notok=true;
		for (var i=0; i < formStr.length; i++)
  	 	{
   		if (formStr[i].checked)
      		{
     		 Notok=false;
     		 }
		}
		if (Notok)
		{
			alert("Please choose "+value);
			//select(formStr);
		}
		return Notok
	}
	//return false
}

function isEmptyInFormTel(formStr,value) {
	Notok=true;
	for (i=0;i<formStr.length;i++)
	{
		//alert(formStr[i].type);
		if (formStr[i].type=="text")
			Notok=Notok&(formStr[i].value=="");
		else if (formStr[i].type=="checkbox" || formStr[i].type=="radio")
			Notok=Notok&(!formStr[i].checked);
	}
	if (Notok)
	{
	alert ("Please enter "+value);
	return true;
	}
	return false;
	//return false
}

function select(field) {
	if (field != null) {
		field.focus()
		//field.select()
	}
}