function getconfirmation(theform)
{
	
	theform.pagenavigate.value="confirmation";	
	theform.prod_id.value=theform.productid.value;
//	theform.catid.value=theform.catid.value;
	theform.submit();
}
function getprodimg(theform)
{

	theform.pagenavigate.value="imageform";
	
//	theform.catid.value=theform.catid.value;
//	theform.productid.value=theform.productid.value;
//	theform.subprodid.value=theform.subprodid.value;
//	theform.parent_catid.value=theform.parent_catid.value;
	theform.action.value=theform.action.value;
	
	theform.submit();
}



function getprod_info(theform)
{

	if(theform.action.value=="add")
	{
	theform.pagenavigate.value="Addprodinfo";
	}
	if(theform.action.value=="modify")
	{
	theform.pagenavigate.value="modifyprodinfo";
	}
	//theform.category_ids.value=theform.chk_cat.value;
	theform.submit();
}
function getprodinfo(theform)
{

	if(theform.action.value=="add")
	{
	theform.pagenavigate.value="Addprodinfo";
	}
	if(theform.action.value=="modify")
	{
	theform.pagenavigate.value="modifyprodinfo";
	}
//	theform.category_ids.value=theform.catid.value;
//	theform.catid.value=theform.catid.value;
	theform.submit();
}
function submit_login_form1()
{
	return check_blank(document.frmlogin.uname,"Enter Username");
	return check_blank(document.frmlogin.pwd,"Enter Password");
}

function check_blank1(object,msg)
{
	if(object.value=="")
	{
		alert(msg);
		object.focus();
		return false;
	}
	return true;
}

function addsubcategory(catid)
{
	document.frmcat.pagenavigate.value="Add";
	document.frmcat.category_ids.value=catid;
	document.frmcat.submit();
}

function changecat()
{


	document.frmcategory.parent_catid.value=document.frmcategory.parent_ids.value;
	document.frmcategory.catid.value=document.frmcategory.catid.value;
	document.frmcategory.childcat.value=document.frmcategory.childcat.value;
	if(document.frmcategory.action.value=="Add")
	{
		document.frmcategory.pagenavigate.value="Addlist";
	}
	if(document.frmcategory.action.value=="Modify")
	{
		document.frmcategory.pagenavigate.value="Modifylist";
	}
	document.frmcategory.submit();
}

function changeprodcat(theform)
{


	theform.parent_catid.value=theform.parent_id.value;
	theform.productid.value=theform.productid.value;
	if(theform.action.value=="add")
	{
		theform.pagenavigate.value="Addlist";
	}
	if(theform.action.value=="modify")
	{
		theform.pagenavigate.value="Modifylist";
	}
	theform.submit();
}

function changeprodfiles(theform)
{
//	theform.parent_catid.value=theform.parent_id.value;
//	theform.productid.value=theform.productid.value;
	if(theform.action.value=="add")
	{
		theform.pagenavigate.value="AddFilelist";
	}
	if(theform.action.value=="modify")
	{
		theform.pagenavigate.value="ModifyFilelist";
	}
	theform.submit();
}

function checkform(theForm) {
    var why = "";
    why += checkEmail(theForm.email.value);
    why += checkPhone(theForm.phone.value);
    why += checkPassword(theForm.password.value);
    why += checkUsername(theForm.username.value);
    why += isEmpty(theForm.notempty.value);
    why += isDifferent(theForm.different.value);
    for (i=0, n=theForm.radios.length; i<n; i++) {
        if (theForm.radios[i].checked) {
            var checkvalue = theForm.radios[i].value;
            break;
        } 
    }
    why += checkRadio(checkvalue,"Please check");
    why += checkDropdown(theForm.choose.selectedIndex);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

// delete product
function deleteproduct(prod_id)
{
	if(confirm("Are you sure to delete?"))
	{

	document.frmproduct.pagenavigate.value="deleteprod";
	document.frmproduct.prod_id.value=prod_id;
	document.frmproduct.leftcatid.value=document.frmproduct.leftcatid.value;
	document.frmproduct.submit();
	}
}

// modify image
function editimage(prod_id,catid)
{

	document.frmproduct.pagenavigate.value="imageform";
	document.frmproduct.prod_id.value=prod_id;
	document.frmproduct.chk_catidarray.value=catid;
	document.frmproduct.catid.value=catid;
	document.frmproduct.action_edit.value="modify";	
	document.frmproduct.submit();
}



// modify product info
function editproduct(prod_id,catid)
{

	document.frmproduct.pagenavigate.value="modifyprodinfo";
	document.frmproduct.prod_id.value=prod_id;
	document.frmproduct.leftcatid.value=document.frmproduct.leftcatid.value;
	
	//document.frmproduct.catid.value=catid;
	document.frmproduct.action_edit.value="modify";	
	document.frmproduct.submit();
}

// image validation

function image_validate(image,imagetype)
{
 var error = "";
	if(image.value=="")
	{
	error="Please attach an image.\n";
	}
	return error;
}

function image_validate21(image,imagetype)
{
 var error = "";
	if(image.value!="")
	{
		var image1 = new Image();
		image1.src = image.value;
		width=image1.width;
		height=image1.height;
		alert(imagetype);
		if (!/(\.(imagetype))$/i.test(image.value))
		{
		error ="Please attach "+imagetype+" image.\n";
		//image.focus();
		//return false;
		}
		return error;
	}
	else
	{
		return error;
	}
	
}

function isFile(tmp_str,fileTyp)
{
  // Name      : isFile.
  // Purpose   : validation for File extention
  // Inputs    : tmp_str -> string for validations.
  //	         fileTyp -> file extention type.
  // Outputs   : return 1 -> if form field is valid
  //		 return -1 -> if form field is unvalid



if(tmp_str != "")
 {
	var validExt = "no";
	fileStr   = tmp_str;
	intstrLen = fileStr.length;
	intLoc    = fileStr.lastIndexOf(".");
	extVal    = fileStr.substring(intLoc,intstrLen);
	extVal	  = extVal.toLowerCase();
        valExt    = fileTyp;
	var extArry   = valExt.split('//');
	var maxLng    = extArry.length;


	for(i=0;i<maxLng;i++)
	{
	   //alert(extVal);
		if(extArry[i] == extVal)
		{

			validExt  = "yes";
		}
	}
	if(validExt == "no")
	{
	  return -1;
	}
 }
 return 1;
}

function image_validate2(image,msg,ext)
{
var error="";
	if(image.value!="")
	{
	
	var image_field;
	var str_image_field;
	
	var str_file_field = new Array();
	jsfile=ext+", "+image.value+", "+msg;
	
	file_field_id = jsfile;
	tmp_valFile = "";
	str_file_field = file_field_id.split(",");
	
	for(a=0; a<str_file_field.length; a++)
      	{
        	
        	tmp_file_extention = str_file_field[a];
        	
        	
        	a=a+1;
        	tmp_str = str_file_field[a];
        	
        	a=a+1;
        	tmp_err_message = str_file_field[a];
        	if(tmp_str != "")
        	{
        		tmp_validate = isFile(tmp_str, tmp_file_extention);
        		if(tmp_validate == -1)
			{
				var brk       = new RegExp('//','gi');
				tmp_file_extention = tmp_file_extention.replace(brk,", ");
				error  = "Please upload "+tmp_file_extention+" extension file for"+msg+"\n";
			        
          		}
        	}
        	else
		{
		       tmp_valFile = "done";
          	}
      	}
      	}
 	return error;
}


// to set the form checked and unchecked.

function SetChecked(val,chkName) 
{
	dml=document.forms[form];
	len = dml.elements.length;
	var i=0;
	for( i=0 ; i<len ; i++) {
	if (dml.elements[i].name==chkName) {
	dml.elements[i].checked=val;
	}
	}
}


// calls form login page
function submit_login_form(theForm) {
    var why = "";
    why += isEmpty(theForm.uname.value,"Please enter username");
    why += isEmpty(theForm.pwd.value,"Please enter password");
    if (why != "") 
    {
       alert(why);
       return false;
    }   
return true;
}// end of submit_login_form




// calls from submit_change_pwd() from clschangepwd.php
function submit_change_pwd(theForm) {
    var why = "";
    why += isEmpty(theForm.oldpwd.value,"Please enter current password");
	if(theForm.oldpwd.value!="")
	{
	why += checkPasswordnew(theForm.oldpwd.value,"current password");
	}
    why += isEmpty(theForm.newpwd.value,"Please enter new password");
	if(theForm.newpwd.value!="")
	{
	why += checkPasswordnew(theForm.newpwd.value,"new password");
	}
    why += isEmpty(theForm.confirmpwd.value,"Please enter confirm password");
	if(theForm.confirmpwd.value!="")
	{
	why += checkPasswordnew(theForm.confirmpwd.value,"confirm password");
	}
    if((theForm.newpwd.value!="")&&(theForm.confirmpwd.value!=""))
    {
    why += compareValues(theForm.newpwd.value,theForm.confirmpwd.value,"New and confirm password should be same");
    }

    if (why != "") 
    {
       alert(why);
       return false;
    }   
return true;
}// end of submit_login_form



// check two values should be same
function compareValues(firstval,secondval,msg)
{
var error="";
	if(firstval!=secondval)
	{
	error=msg+"\n";	
	}
	return error;
}

// check two values should be same
function compareGreterValues(firstval,secondval,msg)
{
var error="";
	if(firstval>=secondval)
	{
	error=msg+"\n";	
	}
	return error;
}

// email

function checkEmail (str) 
{
	var error="";
	if (str == "") 
	{
		error = "You didn't enter an email address.\n";
	}
	
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(str))) 
	{ 
		error = "Please enter a valid email address.\n";
	}
	else {
	//test email for illegal characters
	//var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)

		if (str.indexOf(at)==-1){

		  error="Email address contains illegal characters\n";
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

		   error="Email address contains illegal characters\n";
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

		     error="Email address contains illegal characters\n";
		}

		 if (str.indexOf(at,(lat+1))!=-1){

		     error="More than one @ is not allowed in Email Address\n";
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

		    error="Email address contains illegal characters\n";
		 }

		 if (str.indexOf(dot,(lat+2))==-1){

		     error="Email address contains illegal characters\n";
		 }

		 if (str.indexOf(" ")!=-1){

		    error="Email address contains illegal characters\n";
		 }

	   /*if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(tmp_str)))
	    { 
	      return -1;
            }*/

	//if (strng.match(illegalChars)) {

}

return error;    
}

function checkboxvalidate(dml,chkName,chkboxvalidation){

len = dml.elements.length;
var i=0;
nothing ='';
for( i=0 ; i<len ; i++) {
if ((dml.elements[i].name==chkName) && (dml.elements[i].checked==1)) return(nothing);}
    chkboxvalidation +="\n";
	return(chkboxvalidation);

}

// phone number - strip out delimiters and check for 10 digits
function checkPhone (strng,strname) {
var error = "";
if (strng != "") {
    

 var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]\+\.\=]/
         if (strng.match(illegalChars)) {
          error = strname+ " contains illegal characters. \n";
       }
   else
	{
	var stripped = strng.replace(/[\-\ ]/g, ''); //strip out acceptable non-numeric characters  || stripped.search(/(a-z)+/) || stripped.search(/(A-Z)+/)
//alert(stripped);
    if (isNaN((stripped)) ) {
       error = strname+ " contains illegal characters. \n";
  
    }
	}	
   
}
return error;
}
//function for post code
function checkpostcode(strng,pd)
{
var error = "";
	var exppostcode=/[^\(0-9)|\+|\-]+/;
	
	if(exppostcode.test(strng))
	  {
	 error = "Invalid Pin code entered\n The allowed characters are +,-\n";
	
	}
	return error;
}
// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng,dd) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
}

  //  var illegalChars = /[\W_]/; // allow only letters and numbers
  var illegalchars =/[\s]+/;
    
   // if ((strng.length < 6) || (strng.length > 8)) {
   //    error = "The password is the wrong length.\n";
   // }
   // else 
	
	if (illegalchars.test(strng)) {
      error = "Space is not allowed in password.\n";
    } 
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }  
return error;    
}    

// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPasswordnew (strng,strname) {
var error = "";
if (strng == "") {
   error = "You didn't enter a "+ strname+".\n";
}

  //  var illegalChars = /[\W_]/; // allow only letters and numbers
  var illegalchars =/[\s]+/;
    
   // if ((strng.length < 6) || (strng.length > 8)) {
   //    error = "The password is the wrong length.\n";
   // }
   // else 
	
	if (illegalchars.test(strng)) {
      error = "Space is not allowed in "+ strname+".\n";
    } 
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       error = "The "+ strname+" must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }  
return error;    
}    

//check username
function checkusername (strng,dd) {
var error = "";
if (strng == "") {
   error = "You didn't enter a username.\n";
}

  //  var illegalChars = /[\W_]/; // allow only letters and numbers
  var illegalchars =/[\s]+/;
    
   // if ((strng.length < 6) || (strng.length > 8)) {
   //    error = "The password is the wrong length.\n";
   // }
   // else 
	
	if (illegalchars.test(strng)) {
      error = "Space is not allowed in username.\n";
    } 
    
return error;    
}  

// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername (strng) {

var error = "";
if (strng == "") {
   error = "You didn't enter a username.\n";
}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 10)) {
       error = "The username is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.\n";
    } 
return error;
}       


// non-empty textbox

function isEmpty(strng,msg) {

var error = "";
  if (strng.length == 0) {
     error = msg+"\n";
  }
return error;	  
}

// non-empty textbox

function isInt(strng,msg,msg1) {

var error = "";

  if (strng.length == 0) {
     error = msg1+"\n";
  }
  else if (isNaN(strng)==true) 
  {
     error = msg+"\n";
  }
  else if(parseInt(strng)<=0)
  {
  	error=msg+"\n";
  }
return error;	  
}

//  price validation
function isPrice(strng,msg,msg1) 
{
	var error = "";
	if (strng.length == 0) {
	     error = msg1+"\n";
 	 }
 	 else if(isInt(strng,msg,msg1))
 	 {
 	 error= msg+"\n";
 	 }
	else if(isPrice_check(strng)==1)
	{
		error= msg+"\n";
	}
	return error;
}

function isPrice_check(numval)
{
 itPr = 1;

 //alert("sss");
if(numval==0)
{
itPr = 1;
}
else
{
  num = numval;

  PRLen = num.length;
  Len  = num.lastIndexOf(".");
  Len1  = num.lastIndexOf("-");
  extVal = num.substring(Len+1,PRLen);
//alert("hi");
  if(Len>0)
  {
  	tmp_int_digit = (PRLen-Len);
  }
  else
  {
  	tmp_int_digit = 0;
  }

  //alert(tmp_int_digit);

  num = num.toString().replace(/\$|\,/g,'');
  //num = num.toString().replace(/\$|/g,'');


  if(isNaN(num))
  num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
  cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  num = num.substring(0,num.length-(4*i+3))+','+
  num.substring(num.length-(4*i+3));
  newprice = (num + '.' + cents);
  //alert (newprice);
  //alert(Len1);

  //alert(sign);


  if(newprice == "0.00")
  {
  itPr = 1;
  }

 if((Len != -1)&&(extVal.length > 1))
 {
  itPr  = 0;
 }
}
  return itPr;
}

// was textbox altered

function isDifferent(strng) {
var error = ""; 
  if (strng != "Can\'t touch this!") {
     error = "You altered the inviolate text area.\n";
  }
return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue,msg) {
var error = "";
   if (!(checkvalue)) {
       error = msg+".\n";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice,msg) {
var error = "";
    if (choice == "") {
    error = "Please select "+msg+".\n";
    }    
return error;
}
//reset form
function reset(f)
{
 	oEdit0.loadHTML(f);
}
//order form form
function validateorderform(f)
{
 	if((document.f.nametosearch.value == "") &&
		(document.f.frm_dt_Start.value =="") &&
		(document.f.frm_dt_End.value =="") &&
		(document.f.frm_dt_crtidS.value =="") && 
		(document.f.frm_dt_crtidE.value ==""))
	{

		alert("Please,enter Search category!");
		document.f.nametosearch.focus();
		return true;
	}
return false;
}

function isAlphaString(tmp_str,msg)
{
   var error = "";
  // Name      : isAlpha.

  // Purpose   : allow user to enter only Alpha(A-Z) values.
  // Inputs    : tmp_str -> string for validations.
  // Outputs   : return 1 -> if form field is alphabetic
  //		 return -1 -> if form field is not alphabetic

//ignore validation if tmp_str is blank.
if(tmp_str != "")
 {
  // searching whole string word by word
    if (tmp_str.search)
    {
        //checking the words in string.
        //  if string contains the non alphabetic value, return -1.
        //  else return 1.

	  	if ((tmp_str.search((/[a-zA-Z]/)) != -1) && (tmp_str.search((/[0-9]/)) == -1)&& (tmp_str.search(/[^\w\s]/) == -1))
	  	{
	 		return error;
	  	}
	  	else
	  	{
	  		error = error = msg+".\n";
	  	}

    }
 }
 return error; 
}


 