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;
	}
}

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 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)
function editimage(test_id)
{

	document.frmtestimonial.pagenavigate.value="imageform";
	document.frmtestimonial.test_id.value=test_id;
	//document.frmtestimonial.chk_catidarray.value=catid;
	//document.frmtestimonial.catid.value=catid;
	document.frmtestimonial.action.value="modify";	
	document.frmtestimonial.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");
    why += isEmpty(theForm.newpwd.value,"Please enter new password");
    why += isEmpty(theForm.confirmpwd.value,"Please enter 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;	
	}
	return error;
}

// email

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

// email

function checkEmail2 (strng) {
var error="";
if (strng == "") {
   error = "";
}
else
{
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
 }
return error;    
}

function checkboxvalidate(dml,chkName,chkboxvalidation){

len = dml.elements.length;
var i=0;
for( i=0 ; i<len ; i++) {
if ((dml.elements[i].name==chkName) && (dml.elements[i].checked==1)) return true
}
	retrun(chkboxvalidation);

}

// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "Please enter a Phone number.\n";
}
else{
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The Phone number contains illegal characters.\n";
    }
    //if (!(stripped.length >= 12)) {
	//error = "The phone number is the wrong length. Make sure you included an area code.\n";
    //} 
}
return error;
}

// phone number - strip out delimiters and check for 10 digits

function checkPhone2 (strng) {
var error = "";
if (strng == "") {
   error = "";
}
else{
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The Phone number contains illegal characters.\n";
    }
  //  if (!(stripped.length == 10)) {
	//error = "The phone number is the wrong length. Make sure you included an area code.\n";
  //  } 
}
return error;
}

function isFax (strng) {
var error = "";
if (strng != "") {
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The fax number contains illegal characters.\n";
    }
  //  if (!(stripped.length == 10)) {
	//error = "The phone number is the wrong length. Make sure you included an area code.\n";
  //  } 
}
return error;
}
// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if ((strng.length < 6) || (strng.length > 8)) {
       error = "The password is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\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;    
}    


// 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) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the drop-down list.\n";
    }    
return error;
}    

// checking new and confirm password are 

function chkNewConfirmPwd(strng1,strng2,msg) {

var error = "";
  if (strng1 != strng2) 
  {
     error = msg+"\n";
  }
 
return error;	  
}


 function isUrl(s,msg) {
	 var error="";
// var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/  


var regexp=/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?/

 if(!regexp.test(s))  
	{
             error=msg+" \n";
	}
	if(error=="")
	{
		 var illegalChars= /[\,]/
          if (s.match(illegalChars)) {
           error=msg+" \n";
        }
	}
	 return error; 
 } 
 
  function reset_fck(tmp_str_resetFckName,FckVal)
  {
   /* Name     	: reset            */
   /* Purpose 	: reset FCK editor element in form     */
   /* Inputs   	: news = FCKeditor text
    				  news1 = FCKeditor1 text       */
   /* Outputs  	: FORM ELEMENT ARE RESET           */
   /* Calls    	: 						             */
   /* Called By  : 						               */
 
   		var oEditor = FCKeditorAPI.GetInstance(tmp_str_resetFckName) ;
   		
 		if(FckVal == ''){
 			try{
 				if(document.getElementById('hidPrevContent')){
 
 					val = document.getElementById('hidPrevContent').value;
 	
 					while(val.indexOf('~') > -1)
 						val = val.replace('~','\r\n');
 				}
 				else
 				{
 				val = '';
 				}
 			}
 			catch(e){
 				val = '';
 			}
 		}
 		else	
 			val = FckVal
   		
   		oEditor.SetHTML(val);	
 
}



function compare_dates_bdate(dat1,dat2,msg)
{
//alert(dat1+"\n"+dat2);
  var flag = 0;

  dat1 = dat1.toString();
  var dtSplt1 = dat1.split("/");
  dat2 = dat2.toString();
  var dtSplt2 = dat2.split("/");

  var eYr = parseInt(dtSplt2[2],10);
  var eMn = parseInt(dtSplt2[1],10);
  var eDy =parseInt(dtSplt2[0],10);

  var sYr = parseInt(dtSplt1[2],10);
  var sMn = parseInt(dtSplt1[1],10);
  var sDy = parseInt(dtSplt1[0],10);

    if(eYr == sYr)
    {
	// alert("hi");
        if(eMn == sMn)
        {
		 // alert("hi");
            if(eDy > sDy   )
            {
              //alert("hi");
              flag = 1;
            }
        }
        else if(eMn > sMn)
        {
          flag = 1;
            }
    }
    else if(eYr > sYr)
    {
      flag = 1;
    }

    if(!flag == 1)
    {
      return msg+"\n";
    }
    else
    {
    return "";
    }
    
}
