/*****************************************************************************/

function addtocart(prodid, catid)
{
	var msg="";
	//msg=confirm("This product will be added \n to your shopping cart.\nContinue?");
	//if(msg)
		//{
			window.location.href="addtocart.php?prodid="+prodid+"&catid="+catid;
		//}
}

/*****************************************************************************/

function viewdetails(prodid, catid, lid)
{
	window.location.href="viewselectedproduct.php?id="+prodid+"&left_id="+catid+"&catid="+lid;
}

/*****************************************************************************/
function deleteprod(prodid)
{
	window.location.href="deleteproduct.php?prodid="+prodid;
}
/*****************************************************************************/

function login()
{
	var msg="";

  if(document.loginfrm.username.value.length==0)
	msg+="Enter Username!\n";
  if(document.loginfrm.password.value.length==0)
	msg+="Enter Password!\n";

	if(msg.length>0)
	{
		alert(msg);
		return false;
	}
	else
	{			
	//	document.loginfrm.submit();
		return true;
	}

}

/***************************************************************************/
function registration_a()
{
var msg = "",dc = document.registerfrm;

if(dc.firstname.value.length==0)
	msg+="Enter First Name\n";

if(dc.lastname.value.length==0)
	msg+="Enter Last Name\n";

if(dc.email.value.length==0)
	msg+="Enter Email\n";

if(dc.email.value.length > 0)
	msg += checkmail(dc.email,"string");

if(dc.adm_username.value.length==0)
	msg+="Enter Username\n";

if(dc.adm_password.value.length==0)
{
	msg+="Enter Password\n";
}
else
{
	if(dc.adm_password.value != dc.cadm_password.value)
	msg+="Passwords does not match\n";
}

if(msg.length>0)
{
	alert(msg);
	return false;
}
else
	return true;		


}


function registration()
{
	// for registration
	var msg;
	msg ="";
/*
	for(i=0;i<document.regfrm.elements.length;i++)
		{
			if(document.regfrm.elements[i].value.length==0)
			 {
			 	msg="Enter all Fields!";
				break;	
			 }		
		}	

*/

  //if(document.regfrm.username.value.length==0)
	//msg+="Enter Username!\n";
  
 // if(document.regfrm.password.value.length==0)
	//msg+="Enter Password!\n";

 // if(document.regfrm.password.value != document.regfrm.cpassword.value)
	//msg+="Passwords does not match!\n";

  if(document.regfrm.firstname.value.length==0)
	msg+="Enter First Name!\n";

  if(document.regfrm.lastname.value.length==0)
	msg+="Enter Last Name!\n";

  if(document.regfrm.email.value.length==0)
	msg+="Enter Email!\n";

  //if(document.regfrm.street.value.length==0)
	//msg+="Enter Street!\n";

  if(document.regfrm.city.value.length==0)
	msg+="Enter City!\n";

  if(document.regfrm.state.value.length==0 )//290307&& document.regfrm.country.value == "US")
	msg+="Enter State!\n";

  if(document.regfrm.zipcode.value.length==0)
	msg+="Enter Zip Code!\n";

  if(document.regfrm.country.value.length==0)
	msg+="Enter Country!\n";

 /*290307 if(document.regfrm.country.value!="US")
	document.regfrm.state.value="";*/

  if(document.regfrm.phone.value.length==0)
	msg+="Enter Phone!\n";

//070705 - to validate cc details in member detail form - start
var validate_ccdet = 0;

	for(i=0;i<document.regfrm.elements.length;i++)
		{
			if(document.regfrm.elements[i].name == "redirect_toconfirmorder")
			 {
			 	if(document.regfrm.redirect_toconfirmorder.value == "1")	
				{
				validate_ccdet = 1;
				break;	
				}
			 }		
		}	

if(validate_ccdet == 1)
{

  if(document.regfrm.ssl_card_number.value.length==0)
	msg+="Enter credit card number!\n";

  if(document.regfrm.ssl_exp_date.value.length==0)
	msg+="Enter card expiry month and year!\n";

  if(document.regfrm.ssl_cvv2.value.length==0)
	msg+="Enter CVV2/CVC2 Indicator!\n";

}

//070705 - to validate cc details in member detail form - end

	if(msg.length > 0)
	{
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}	
}

/***************************************************************************/


//	TO SELECT FROM SELECTION BOX
function selectmenu(obj,val)
{

  var len=obj.options.length

  for(var i=0;i<len;i++)
  {
    if(obj.options[i].value==val)
     {
       obj.selectedIndex=i;
     }
  } 
}

/***************************************************************************/

function forgotpassword()
{
//120407 - removing username alert
  if(document.forgotpass_frm.temailaddress.value=="")
  {
    alert("Enter Email address");
	return false;
  }
	else
	{
		return true;	
	}
}

 /**************************EMAIL CHECKING***************************/
 
 function checkmail(fldname,dothis)
  {  

	//for all email fields in any forms - BOTH FOR ADMIN/USERS
	
	var msg = "";  	
	email = fldname.value;

	var len = email.length;              

	if(len<5)
		{
			msg += "Invalid Email - id!\n";
		}
	else
		{
          
	var index1 = email.indexOf('@');
	var subind = email.substring(0,index1);
	var indlen = subind.length;
	var index2 = email.indexOf('.');
	var subind1=email.substring(indlen+1,index2);
	var indlen1 = subind1.length;
	var index3 = email.indexOf(' ');
	var subind3=email.substring(index2+1,len)
	var indlen2 = subind3.length;
	if((index1!= -1)&&(index2!= -1)&&(index3==-1))
	{	
		if((indlen!=0)&&(indlen1!=0)&&(indlen2!=0))
		{
//   			alert("valid Email -id");		  	 	
		} 
        else
		{
			msg += "Invalid Email - id!\n";
		}
	}
	else
	{
   		msg += "Invalid Email - id!\n";
	}		
	} // end of else if len<5

	if(dothis == "string")
	{
		return msg;
	}

	if(msg.length > 0)
	{
			fldname.value="";
			
			alert(msg);
	}

  }	

/***************************************************************************/
function numcheck(obj,val)
  {
    var msg = "";
    if(isNaN(obj.value)|| (obj.value.indexOf(' ')!=-1))
	{
	  msg = "Enter numeric values!\n";
          obj.value = "";          
    }
	
	if(val == "string") //changed on 240805
	return msg;

    if (obj.value <= 0)
	{
	  obj.value = "";
	}
        
	
    if(msg.length > 0)
		alert(msg);

  }
/*****************************************************************************/
function popupwindow(obj)
{
	window.open(obj, '', "scrollbar=no, menu=no, status=no, resizable=no, width=350, height=400");
}
/***************************************************************************/


/***********************************************************************************/

function addcat()
{

	var message="";
	if(document.addcategoryfrm.catname.value=="")
		message=message + "Enter Category Name!\n";

	if(message.length >0)
	{
		alert(message);
		return false;
	}
	else
	{
		//document.addcategoryfrm.submit();
		return true;
	}
}

function addman()
{

	var message="";
	if(document.manufacturer_frm.supplier_name.value=="")
		message=message + "Enter Supplier Name!\n"

	if(message.length >0)
	{
		alert(message);
		return false;
	}
	else
	{
		//document.addcategoryfrm.submit();
		return true;
	}
}


/***********************************************************************************/

function addsubcat()
{

	var message="";
	if(document.addcategoryfrm.subcatname.value=="")
		message=message + "Enter Subcategory Name!\n"

	if(message.length >0)
	{
		alert(message);
		return false;
	}
	else
	{
		//document.addcategoryfrm.submit();
		return true;
	}
}



 
/***********************************************************************************/

/**********************search by product in index**********************************/
function search_index_prod()
{
if(document.search_prodfrm.product.value.length==0)
alert("Please enter a product name to search!");
else
document.search_prodfrm.submit();
}

function search_prod_code()
{
if(document.prod_code.code.value.length==0)
alert("Please enter a product code to search!");
else
document.prod_code.submit();
}

function admin_search()
{
if(document.price_cat.cat_search.value.length==0)
alert("Please choose a category to search!");
else
document.price_cat.submit();
}

function add_product(option)
{

	var msg="";
/*
	if(document.addproductfrm.category.value < "0")
		msg=msg + "Choose a subcategory name!\n"
*/	
	for(i=0;i<document.addproductfrm.elements.length;i++)
	{
		if(document.addproductfrm.elements[i].name=="category[]")
			{
				if(document.addproductfrm.elements[i].value==-1 || document.addproductfrm.elements[i].value.length==0)
				 {	
					msg+="Choose a Product category!\n";	
					break;
				 }
			}			
	}
	
/*280307 
	if(document.addproductfrm.code.value.length==0)
	
			msg+="Enter Product Code!\n";
*/	
	if(document.addproductfrm.name.value.length==0)
			msg+="Enter Product Title!\n";
			
//200407 - start
	if(document.addproductfrm.group1_price.value.length==0)
		msg+="Enter Product Price!\n";
		
	if(document.addproductfrm.weight.value.length==0)
		msg+="Enter Product Weight!\n";	
//200407 - End
			
//To make a product parent, it is compulsory to choose a product option.
	validate_optionset=false;
	if(document.addproductfrm.parent_id.value=="-1" && document.addproductfrm.id.value.length == 0)
	{ //ask to choose optionssets.
		
		validate_optionset=true;
		for(i=1;i<=document.addproductfrm.max_optionset.value;i++)
		{
		
			field_name="product_option"+i;
			
			if(eval("document.addproductfrm."+field_name+".value.length > 0"))
			{
			validate_optionset=false;
			break;
			}
		
		}
	
	} //end if(document.addproductfrm.parent_id.value=="-1")
	else if(document.addproductfrm.parent_id.value > 0)
	{ //the admin user is about to add a child product, hence validate such that the user is prompted to choose values for all option sets.

		for(i=1;i<=document.addproductfrm.max_optionset.value;i++)
		{
		
			field_name="product_option"+i;
			
			if(eval("document.addproductfrm."+field_name+".value.length == 0"))
			{
			//validate_optionset=false;
			msg+="Please choose all available options!\n";
			break;
			}
		
		}
	
	}


	if(validate_optionset)
		msg+="Please select a optionset!\n";
			
/*
	if(document.addproductfrm.description.value.length==0)
			msg+="Enter Product description!\n";
*/	


	if(msg.length >0)
	{
		alert(msg);
		return false;
	}
	else
	{
		//280307 chk_freeprod();
		return true;
	}
	
	
	
}

//function to check whether a value is in an particular array
function check_arr(str,val)
{


var arr = new Array();

arr=str.split("|");
arr_count=arr.length;
//alert(val+"incheck arr");

	for(i=0;i<=arr_count;i++)
	{
	
//		alert(val+" inside check array");
//		alert(arr[i]+" inside check array");
		
		if(val==arr[i])
		{
			return true;
			break;
		}
	//	else
	//		return true;
		
	}

return false;

}	//end function check_arr
//function to check whether a value is in an array


/***************************todays registration for admin*************************/

function today_registration(regd)
{
//alert(regd);
	window.location.href="member_main.php?list="+regd+"&purpose="+document.member_search.purpose.value;
}

function edit_option(id,pid)
{
window.location.href="prodoption.php?parent="+pid+"&optid="+id+"&chk="+1;
}

function del_option(id,pid)
{
window.location.href="prodoption.php?delete="+id+"&parent="+pid;
}

function show_prod(id,parent,optionid,catid)
{
window.location.href="editproduct.php?parent="+id+"&parent_id="+parent+"&option_id="+optionid+"&child=1&catid="+catid;
}

function set_spec(pid,catid,val)
{
if(val > 0)
window.location.href="editproduct.php?parent="+pid+"&catid="+catid+"&specify="+val;
}


/*****************************Discount Validations**************************************/

function discount_settings()
{
var msg="";
	if(document.discount.discount_code.value.length==0)
			msg+="Enter Discount Code!\n";

	if(document.discount.discount_value.value.length==0)
			msg+="Enter Discount Value!\n";
/*290507
	if(document.discount.discount_type.value.length==0)
		msg+="Enter Discount Type!\n";
*/		

	if(document.discount.date.value==0)
			msg+="Enter Date!\n";

	if(document.discount.month.value==0)
			msg+="Enter Month!\n";

	if(document.discount.year.value==0)
			msg+="Enter Year!\n";

	if(msg.length > 0)
	{
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
}


//***********************function for newsletter - 041104

function nl_validate()
{

if(document.choose_nl.nlid.value.length==0 || document.choose_nl.template_id.value.length==0)
{
	alert("Please choose a newsletter and a template!\n");
	return false;
}
else

	return true;

}

//051104 - function for rating - start

function rate_this(id,field)
{

	var str="";
	str+="document.viewprod"+id+"."+field+".value='yes'\;";
	str+="document.viewprod"+id+".submit()\;";
	
	eval(str);

}

function viewdetails_rate(prodid, catid, lid)
{
	window.location.href="viewselectedproduct.php?id="+prodid+"&catid="+catid+"&left_id="+lid+"#rate";
}

//the following function is purposely for leftnav and indexpages
function rate_this_navindex(frmname,id,catid)
{
	var str="";
	str="document."+frmname+".user_rating.value='yes'\;";
	str+="document."+frmname+".submit()\;";
	
	eval(str);
	
}


//051104 - function for rating - end



function add_remove_customer(obj,uname)
{

var page_all_user,temp_page_all_user="";
var all_user_search;
var page_user_array = new Array();
//alert(uname);
//alert(document.records.add_del_cust.value);

page_all_user=document.records.add_del_cust.value;

page_all_user_selected=document.records.selected_cust.value;

all_user_search=document.records.selected_cust.value;

temp_page_all_user=document.records.selected_cust.value;


		if(obj.checked==true)
		{
			temp_page_all_user+=uname+"|";
		}
		else
		{		
				temp_page_all_user="";
				page_all_user_selected_arr=page_all_user_selected.split("|");
				for(j=0;j<(page_all_user_selected_arr.length);j++)
				{
					//alert(page_all_user_selected_arr[j]+" uncheck");
					
					if(page_all_user_selected_arr[j]!=uname)
					{
						if(page_all_user_selected_arr[j].length > 0)
						temp_page_all_user+=page_all_user_selected_arr[j]+"|";
					}
					
				}

		}



		document.records.selected_cust.value=temp_page_all_user;


}

//091104 - function for paging member_main.php in newsletter case - start

function confirm_on_del(val)
{

	if(val.length==0)
	{
		if(confirm('Are you sure?'))
			return true;
		else
			return false;
	}
	else
	{
		if(confirm(val))
			return true;
		else
			return false;
	}
}

function alert_delete(val1,val2,val3)
{

if(confirm_on_del(''))
{
str=val2+"&id="+val1+"&type="+val3;
//alert(str);
window.location.href=str;

}

}

function paging_purpose(val)
{

	document.records.row.value=val;
	document.records.submit();

}

function addoption(val1,val2)
{

var msg="";

if(document.prodoption.name.value.length==0)
	msg+="Enter Option name!\n";

if(val1=="child")
{

	if(val2==0)
		document.prodoption.hidden_action.value="addchild";
	else
		document.prodoption.hidden_action.value="editchild";

}

if(msg.length > 0)
{
	alert(msg);
	return false;
}
else
{
	return true;
}	

}

function validate_staticpage(val)
{

var msg="";

if(document.static_pages.title.value.length == 0)
	msg+="Enter title!\n";

if(val <=0 && document.static_pages.description.value.length == 0)
	msg+="Enter description!\n";

//240707if(document.static_pages.content.value.length == 0)
	//msg+="Enter content!\n";

if(msg.length > 0)
{

	alert(msg);
	return false;

}
else
{
	return true;
}


}

function newsletter_validate()
{

var msg="";

if(document.newsletterfrm.name.value.length == 0)
	msg+="Enter name!\n";

if(document.newsletterfrm.template_id.value.length == 0)
	msg+="Choose a template!\n";

if(msg.length > 0)

{
	alert(msg);
	return false;
}

else

{
	return true;
}


}


function template_validate()
{

var msg="";

if(document.templatefrm.name.value.length == 0)
	msg+="Enter name!\n";

if(document.templatefrm.content.value.length == 0 && document.templatefrm.txt_content.value.length == 0)
	msg+="Enter content!\n";

if(msg.length > 0)

{
	alert(msg);
	return false;
}

else

{
	return true;
}


}

function mailinglist()
{

var msg="";

if(document.regfrm.member_email.value.length == 0)
	msg+="Enter email!\n";

if(msg.length > 0)
{
	alert(msg);
	return false;
}

else

{
	return true;
}


}

//function to validate for specification and optionsets on user side while ordering

function validate_product_list(val, rttyp, ptyp)
{


if(val <= 0)
	return false;

var msg="";

var dc="", field_name="";

var option_value="";

var validate_stock;

if(usage_stock_fill)
	validate_stock = true;
else
	validate_stock = false;

dc=eval("document.product_frm"+val);

field_name = dc.what_to_validate.value;

if(dc.validate_field_count.value > 0)
{

	for(i=1;i<=dc.validate_field_count.value;i++)
	{
		
		temp_field_name=field_name+i;
		
		if(eval("dc."+temp_field_name+".value") == 0)
		{
			//msg+="Please select all available "+field_name+"!\n";
			
			if(ptyp == "main")
				msg += "Please select all available product options to order!\n";
			else
				msg += "Please select all available product options of the free product!\n";

			validate_stock = false;
			break;
		}
		else
		{
			option_value+=eval("dc."+temp_field_name+".value")+"|#|";
		}

	}

}


//we need to say whether the chosen option exists for the product...

if(field_name == "optionset")
{

//alert(dc.existing_options.value);

split_value=option_value.substring(0,(option_value.length-3)); //the chosen options is got by truncating the last added "|#|" symbol.

/**********

If we split the existing option string with this chosen option value, the array length will be 2 if the chosen option is available, else if the array count or length is "1" then the chosen option is not available.

*************/

existing_option_arr=dc.existing_options.value.split(split_value);

	if(existing_option_arr.length < 2)
	{
	 	
		if(ptyp == "main")
	 		msg += "The option you have chosen for this product is currently unavailable\n";
		else
			msg += "Chosen options for the free product is not available!\n";
		validate_stock = false;
	
	} //end if
	//alert(validate_stock);
	if(validate_stock)
	
	{ //if the child product exists then check for the available quantity
	
	/* To check stock for the child product another hidden field "child_stock_available" has been set like this "3;5;24;....". In this string the first number is the available stock for the first option set in the hidden field "existing_options". NOTE: "split_value" is the chosen option. */
	
			temp_existing_option = dc.existing_options.value;
			
			temp_exist_opt_array = temp_existing_option.split(";");
			
			temp_existing_option_stock = dc.child_stock_available.value;
			
			temp_exist_stock_array = temp_existing_option_stock.split(";");
			
			for(i=0;i<temp_exist_opt_array.length;i++)
			{
			
				if(temp_exist_opt_array[i]==split_value)
				{
					/*
					alert(temp_exist_stock_array[i]);
					alert(dc.quantity.value);
					*/
					
					if(Math.abs(temp_exist_stock_array[i]) < Math.abs(dc.quantity.value))
					{
						if(ptyp == "main")
							msg+= "Stock not available for the chosen product option!\n";
						else
							msg += "Free product Stock not available for the chosen product option!\n";
						break;
					}
				
				}
			
			}
	
	} //end if validate_stock

}

//if(Math.abs(dc.stock_available.value) < Math.abs(dc.quantity.value) && dc.child_stock_available.value.length == 0 && validate_stock)
if(dc.child_stock_available.value.length == 0 && validate_stock)

{
	if(ptyp == "main")
		msg+= "Stock not available!\n";
	else
		msg+= "Free product Stock not available!\n";
}

/* 290307 commented for avoiding free prodcuts errors
if(dc.free_product_id.value > 0)//if free product exists for the product, and if it has specifications or options we need to validate for that..
msg += validate_product_list(dc.free_product_id.value, "string", "free");


if(rttyp == "string")
{
	if(ptyp == "free")
	{ //need to set the chosen specifications/options/quantity of the free product
		var main_dc = eval("document.product_frm" + dc.main_product_id.value);
		main_dc.free_quantity.value = dc.quantity.value;
		main_dc.free_specification_or_options.value = dc.what_to_validate.value;
		main_dc.free_specification_options.value = option_value;
	}

	return msg;
}*/

//190407
if(dc.quantity.value.length==0)
	msg+="Please choose Quantity\n";
	
if(msg.length > 0)
{
	alert(msg);
	return false;
}	

else

{
	return true;
}


} //end function validate_product_list


function contact_msg()
{

var msg = "", prefix;

prefix = document.contact_frm;

	if(prefix.frm_email.value.length == 0)
		msg += "Please enter email!\n";
		
	if(prefix.subject.value.length == 0)
		msg += "Please enter subject!\n";
		
	if(prefix.message.value.length == 0)
		msg += "Please enter message!\n";
		
if(msg.length > 0)	
{
	alert(msg);
	return false;
}
else
{
	return true;
}

}

//090408
function validate_shipper_info(val)
{

var msg="",dc;

dc = document.regfrm;

//if(dc.username.value == "none") //if public users we need to validate for billing information
{
//alert(dc.chk_password.value);
  if(dc.firstname.value.length==0)
	msg+="Enter First Name!\n";

  if(dc.lastname.value.length==0)
	msg+="Enter Last Name!\n";

  if(dc.address2.value.length==0)
	msg+="Enter Address!\n";

  if(dc.city.value.length==0)
	msg+="Enter Suburb/City!\n";
	  
  if(dc.state.value.length==0 && dc.country.value == "AU")//110408
	msg+="Enter State!\n";

  if(dc.zipcode.value.length==0)
	msg+="Enter Zip Code!\n";

  if(dc.email.value.length==0)
	msg+="Enter Email!\n";
    	
  else if(dc.email.value.length > 0)
	msg+=checkmail(dc.email,"string");
 
 
  if(dc.phone.value.length==0)
	msg+="Enter Phone!\n";

  if(dc.chk_password.value==1 && val==0)//100408
  {
  
  	if(dc.user_pass.value.length==0)
		msg+="Enter Password!\n";
	else if(dc.user_pass.value.length<6)
		msg+="Password must be atleast 6 characters!\n";//140408
				
	if(dc.retype_pass.value.length==0)
		msg+="Retype Password!\n";	
	else
	{
	
		if(dc.user_pass.value!=dc.retype_pass.value)
			msg+="Password doesn't match!\n";
	}	
  }	
}

//290307  
//  if(dc.ship_method.value.length==0 && dc.ship_country.value == "US")
//	msg+="Choose Shipping Method!\n";

if(val<=0 || 1==1)//280408
{
  if(dc.ship_firstname.value.length==0)
	msg+="Enter shipping First Name!\n";

  if(dc.ship_lastname.value.length==0)
	msg+="Enter shipping Last Name!\n";

  if(dc.ship_address2.value.length==0)
	msg+="Enter shipping Address!\n";

  if(dc.ship_city.value.length==0)
	msg+="Enter shipping suburb/city!\n";

  if(dc.ship_state.value.length==0 )//&& dc.ship_country.value == "US")
	msg+="Enter shipping State!\n";

  if(dc.ship_zip.value.length==0)
	msg+="Enter shipping Zip Code!\n";

  if(dc.ship_country.value.length==0)
	msg+="Choose shipping Country!\n";

  if(dc.ship_phone.value.length==0)
	msg+="Enter shipping Phone!\n";
}
  //if(dc.ship_country.value != "US")
//	dc.ship_method.value="";


  //if(dc.ssl_card_number.value.length==0)
	//msg+="Enter credit card number!\n";

  //if(dc.ssl_exp_date.value.length==0)
	//msg+="Enter card expiry month and year!\n";

  //if(dc.ssl_cvv2.value.length==0)
	//msg+="Enter CVV2/CVC2 Indicator!\n";


	if(msg.length > 0)
	{
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}	


}

function validate_user_nl()
{

	if(document.right_nl_frm.member_email.value.length == 0)
	{
		alert("Please enter a email!");
		return false;
	}
	else
	{
		return true;
	}

}

//to select all customers in that page - function used while selecting mailing list members to send newsletters - 120705
function check_all(frm,sel,val)

{



	for(i=0;i<eval("document." + frm + ".elements.length");i++)

	{

	nam = eval("document." + frm + ".elements[" + i + "].name");



		if(nam.substring(0,3)==val)

		{

		eval("document." + frm + ".elements[" + i + "].checked = " + sel.checked);
		add_remove_customer(eval("document." + frm + ".elements[" + i + "]"),eval("document." + frm + ".elements[" + i + "].value"));

		} //end if==val

	} //end for

} //end function

//to select all customers in that page - function used while selecting mailing list members to send newsletters - 120705

//********************** Js Function for rating feature - Start - 150905

function chk_rating()
{

var msg = "", dc = document.rating_frm;


if(dc.comments.value.length == 0)
	msg += "Please enter comments!\n";


if(msg.length > 0)
{
	alert(msg);
	return false;
}

else

{

	return true;
 
}

} //end function chk_rating - used for rating form on admin panel

function rate_this(id)
{

	var msg="",dc;
	
	dc = eval("document.viewprod"+id);
	
	if(dc.num_spec_or_option.value > 0)
	{ //the product viewed by the user is a parent product, the user can only rate the child products and hence we need to validate to select all optionsets
		
		for(i=1;i<=dc.num_spec_or_option.value;i++)
		{
			
			if(eval("dc.optionset"  + i + ".value.length") == 0)
			{
				msg += "Please choose all available product options to rate this product!\n";
				break;
			}
			
		}
	
	} //
	
	if(dc.comments.value.length == 0)
		msg += "Please enter comments!\n";
	
	if(msg.length > 0)
	{
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}

} //end function rate_this - used for rating on user side.

function setproduct_torate(field_index,field_value,product_id)
{

var str;

str  = "document.viewprod" + product_id + ".optionset" + field_index + ".value = " + field_value;

eval(str);

} //end function setproduct_torate

//********************** Js Function for rating feature - End - 150905


//200306 - function added to save the selection of a list in the next page - Start
function add_remove_listing(obj,uname,frm_name)
{

var page_all_user,temp_page_all_user="";
var all_user_search,final_str;
var page_user_array = new Array();
//alert(uname);
//alert(document.records.add_del_cust.value);

//page_all_user=document.records.add_del_cust.value;
var str1;
str1 = "document." + frm_name + ".selected_checkbox_values.value";
page_all_user_selected=eval(str1);

all_user_search=eval(str1);

temp_page_all_user=eval(str1);


		if(obj.checked==true)
		{
			temp_page_all_user+=uname+"|";
		}
		else
		{		
				temp_page_all_user="";
				page_all_user_selected_arr=page_all_user_selected.split("|");
				for(j=0;j<(page_all_user_selected_arr.length);j++)
				{
					//alert(page_all_user_selected_arr[j]+" uncheck");
					
					if(page_all_user_selected_arr[j]!=uname)
					{
						if(page_all_user_selected_arr[j].length > 0)
						temp_page_all_user+=page_all_user_selected_arr[j]+"|";
					}
					
				}

		}



		final_str = "document." + frm_name + ".selected_checkbox_values.value=\"" + temp_page_all_user + "\"";

		eval(final_str);

}

//200306 - function added to save the selection of a list in the next page - End

//220306 - function for double points feature. - Start

function chk_double_points(frmname)
{

	var dc = eval("document." + frmname), msg = "", users;
	
	if(dc.fmonth.value.length == 0 || dc.fdate.value.length == 0 || dc.fyear.value.length == 0)
		msg += "Select start date!\n";

	if(dc.tmonth.value.length == 0 || dc.tdate.value.length == 0 || dc.tyear.value.length == 0)
		msg += "Select end date!\n";
	
	users = dc.user_ids.value.split("|");
	
	if(dc.user_ids.value.length == 0 && dc.new_existing_ids.value.length == 0)
		msg += "Select users!\n";

	if(msg.length > 0)
	{
		alert(msg);
		return false;
	}
	else
	{
		dc.target = '_self';
		dc.action = 'double_points_action.php';
		return true;
	}

} //end function

//220306 - function for double points feature. - End

function validate_free_product(val)
{


if(val <= 0)
	return false;

var msg="";

var dc="", field_name="";

var option_value="";

var validate_stock;

if(usage_stock_fill && 1==2)//040406 - since we are validating for free products we  need not check for stock..
	validate_stock = true;
else
	validate_stock = false;


dc=eval("document.product_frm"+val);

field_name = dc.fwhat_to_validate.value;

if(dc.fvalidate_field_count.value > 0)
{

	for(i=1;i<=dc.fvalidate_field_count.value;i++)
	{
		
		temp_field_name=field_name+i;
		
		if(eval("dc."+temp_field_name+".value.length") == 0)
		{
			//msg+="Please select all available "+field_name+"!\n";
			msg += "Please select all available product options of free product to order!\n";
			validate_stock = false;
			break;
		}
		else
		{
			option_value+=eval("dc."+temp_field_name+".value")+"|#|";
		}

	}

}


//we need to say whether the chosen option exists for the product...

if(field_name == "optionset")
{

//alert(dc.existing_options.value);

split_value=option_value.substring(0,(option_value.length-3)); //the chosen options is got by truncating the last added "|#|" symbol.

/**********

If we split the existing option string with this chosen option value, the array length will be 2 if the chosen option is available, else if the array count or length is "1" then the chosen option is not available.

*************/

existing_option_arr=dc.fexisting_options.value.split(split_value);

	if(existing_option_arr.length < 2)
	{
	 
	 	msg+="Chosen option is not available!\n";
		validate_stock = false;
	
	} //end if
	//alert(validate_stock);

	if(validate_stock)
	
	{ //if the child product exists then check for the available quantity
	
	/* To check stock for the child product another hidden field "child_stock_available" has been set like this "3;5;24;....". In this string the first number is the available stock for the first option set in the hidden field "existing_options". NOTE: "split_value" is the chosen option. */
	
			temp_existing_option = dc.fexisting_options.value;
			
			temp_exist_opt_array = temp_existing_option.split(";");
			
			temp_existing_option_stock = dc.child_stock_available.value;
			
			temp_exist_stock_array = temp_existing_option_stock.split(";");
			
			for(i=0;i<temp_exist_opt_array.length;i++)
			{
			
				if(temp_exist_opt_array[i]==split_value)
				{
					/*
					alert(temp_exist_stock_array[i]);
					alert(dc.quantity.value);
					*/
					
					if(Math.abs(temp_exist_stock_array[i]) < Math.abs(dc.fquantity.value))
					{
						msg+= "Stock not available for the chosen product option!\n";
						break;
					}
				
				}
			
			}
	
	} //end if validate_stock

}


if(Math.abs(dc.fstock_available.value) < Math.abs(dc.fquantity.value) && dc.fchild_stock_available.value.length == 0 && validate_stock)
{

	msg+= "Stock not available!\n";

}


return msg;


}

//function added while making free products feature.. - 170406
function chk_freeprod()
{
//check and do only if free product subcategories exists..
/* 290307 - commented for aoiding script errors
if(document.addproductfrm.free_pcat_ids.value.length > 0)
{
	var temp_disable = 0;
	subcat_vals = document.addproductfrm.free_pcat_ids.value;
	//alert(subcat_vals);
	for(i=0; i < document.addproductfrm.category.options.length; i++)
	{
			if(document.addproductfrm.category.options[i].selected)
			{
				chk_str = "," + document.addproductfrm.category.options[i].value + ",";
				//alert(chk_str);
				//alert(subcat_vals.indexOf(chk_str));
				if(subcat_vals.indexOf(chk_str) != -1)
				{
					temp_disable = 1;
					break
				}
				
			}
	}

	if(temp_disable == 1)
		document.addproductfrm.free_product_id.disabled = true;
	else
		document.addproductfrm.free_product_id.disabled = false;
	

}*/

}

//280307

function chk_user_frm()

{

	var msg="";

	//230707 -start
	if(document.user_frm.email.value.length==0)
		msg+="Please enter Email Address\n";

	if(document.user_frm.email.value.length > 0)
		msg+= checkmail(document.user_frm.email,"string");

	if(document.user_frm.terms.checked!==true)
		msg+="Please check the terms\n";
	
	if(document.user_frm.other_chkbox_value.checked==true && document.user_frm.others.value.length > 0)
		document.user_frm.other_chkbox_value.value=document.user_frm.others.value;
		
	if(msg.length > 0)

	{

		alert(msg);

		return false;

	}	

	else

	{

		return true;

	}

		

}

//110407
//090408
function chk_password()
{
	
	var msg="";
	
	if(document.password_form.user_pass.value.length==0)
		msg+="Please enter your password\n";
	else if(document.password_form.user_pass.value.length<6)
		msg+="Please enter atleast 6 characters!\n";
	else
	{		
		if(document.password_form.user_pass.value!=document.password_form.vpass.value)
			msg+="Password do not match\n";	
	}		
		
	if(msg.length > 0)
	{
	
		alert(msg);
		return false;	
	}		
	else
		return true;	

}

function chk_cc_details(val)
{

	var msg="";

	

	

	if(document.cc_detail_form.txtCCName.value.length==0)

		msg+="Enter the name on your card!\n";

		

	if(document.cc_detail_form.txtCCNumber.value.length==0)

		msg+="Enter credit card number!\n";



	if(document.cc_detail_form.ddlCardType.value.length==0)

		msg+="Enter choose your card type!\n";

	

  	if(document.cc_detail_form.txtCVN.value.length==0)

		msg+="Enter CVC Number!\n";

		
	if(val<=0)
	{
		document.cc_detail_form.action='cc_payment.php';	
		msg="";
	}	

	if(msg.length > 0)

	{

	

		alert(msg);

		return false;

	}

	else

		return true;		



}

//010507

function validate_link()
{

	var msg="";
	
	if(document.link_frm.title.value.length==0)
		msg+="Enter Title\n";
	
	if(document.link_frm.url.value=="http://")
		document.link_frm.url.value='';
		
	if(document.link_frm.url.value.length==0)
		msg+="Enter your Web Address\n";
		
	if(msg.length > 0)
	{
	
		alert(msg);
		return false;
		
	}
	else
		return true;
						

}

function validate_stockist()
{

	var msg="";
	
	if(document.stockist_frm.store_name.value.length==0)
		msg+="Enter Store Name\n";
	
	if(document.stockist_frm.state.value.length==0)
		msg+="Choose a State/Country\n";//250308
			
	if(document.stockist_frm.url.value=="http://")
		document.stockist_frm.url.value='';
	
		
	if(msg.length > 0)
	{
	
		alert(msg);
		return false;
		
	}
	else
		return true;
						

}

function validate_article()
{

	var msg="";
	
	if(document.article_frm.title.value.length==0)
		msg+="Enter Title\n";
	
	if(document.article_frm.date_of_application.value.length==0)
		msg+="Enter the date of publication\n";
			
			
	if(msg.length > 0)
	{
	
		alert(msg);
		return false;
		
	}
	else
		return true;
						

}

//260507

function chk_mail_tofriend(frmname)
{
	
	var dc, msg="";
	
	dc=eval("document." + frmname);
	
	if(dc.cname.value.length==0)
		msg+="Enter your Name\n";
	
	if(dc.cemail.value.length==0)
		msg+="Enter your Email\n";
		
	if(dc.cemail.value.length > 0)
		msg+= checkmail(dc.cemail,"string");
	
	if(dc.fname.value.length==0)
		msg+="Enter your Friend Name\n";
	
	if(dc.femail.value.length==0)
		msg+="Enter your Friend Email\n";
		
	if(dc.femail.value.length > 0)
		msg+= checkmail(dc.femail,"string");	
			
	if(msg.length > 0)
	{
	
		alert(msg);
		return false;
	}
	else
		return true;	
	
	
}

//230707
function validate_competition()

{

	var dc, msg="";
	
	dc=eval("document.competition_frm");
	
	if(dc.start_date.value.length ==0)
		msg+="Please enter Start Date!\n";
		
	if(dc.end_date.value.length ==0)
		msg+="Please enter End Date!\n";	
	
	if(msg.length > 0)
	{
	
		alert(msg);
		return false;
	}
	else
		return	true;
}
function chk_friends_mail()
{

	var dc;
	
	dc=eval("document.refer_friends_frm");
	
	name_entered=false;
	email_entered=false;
	for(i=0;i<dc.elements.length;i++)
	{
	
		if(dc.elements[i].name=="name[]")
		{			
			if(dc.elements[i].value.length>0 && dc.elements[i].value!="Friend's Name")
			{
				name_entered=true;
				break;
			}	
			
		}	
		
		if(dc.elements[i].name=="email[]")
		{
		
			if(dc.elements[i].value.length>0 && dc.elements[i].value!="Friend's Email")
			{
				email_entered=true;
				break;
			}	
			
		}				
		
	}
	
	if(!email_entered && !name_entered)
	{
		alert("Please enter atleast one's detail!\n");
		return false;
	}		
	else //090408
	{
		for(j=0;j<dc.elements.length;j++)
		{
					
			if(dc.elements[j].name=="name[]" && dc.elements[j].value=="Friend's Name")
				dc.elements[j].value="";		
			
			if(dc.elements[j].name=="email[]" && dc.elements[j].value=="Friend's Email")
				dc.elements[j].value="";	
		}
		return true;
	}	
}

//130208
function discount_system_settings()
{
	var msg=""; 
	
	/*if(document.product_discount.discount_quantity.value.length==0 && document.product_discount.discount_quantity.value<=0)
	
		msg+="Please enter how many user can buy to gain!\n";030408*/
		
/*	if(document.product_discount.product_id.value.length==0)
		msg+="Please choose a Product!\n";

	for(i=0;i<document.product_discount.elements.length;i++)
	{
		name= document.product_discount.elements[i].name;
		
		if(name=="offer_products[]")
		{
		
			if(document.product_discount.elements[i].value.length==0)
				msg+="Please choose products!\n";
		}
	}*/	
	
	if(document.product_discount.discount_value.value.length==0)
		msg+="Please enter Discount Value!\n";//030408
		
	if(document.product_discount.discount_code.value.length==0)
		msg+="Please enter Coupon Code!\n";//030408	
		
	if(document.product_discount.discount_code.value.length > 0)
	{

		if(document.product_discount.month.value==0)
			msg+="Please choose a valid month!\n";
		
		if(document.product_discount.date.value==0)
			msg+="Please choose a valid date!\n";
			
		if(document.product_discount.year.value==0)
			msg+="Please choose a valid year!\n";	
		
		
	}
				
	if(msg.length > 0)
	{
	
		alert(msg);
		return false;
	}
	else
	{
		document.product_discount.expiry_date.value=document.product_discount.year.value+"-"+document.product_discount.month.value+"-"+document.product_discount.date.value;
		//161208 - start
		document.product_discount.valid_from.value=document.product_discount.start_year.value+"-"+document.product_discount.start_month.value+"-"+document.product_discount.start_date.value;
		//161208 - end
		return	true;
	}	
}		

//250308
function validate_location()
{

	var msg="";
	
	if(document.location_frm.name.value.length==0)
		msg+="Enter Location Name\n";
	
	if(msg.length > 0)
	{
		alert(msg);
		return false;
	}
	else
		return	true;
		
}		

//061208
function validate_testimonial()
{

	var msg="";
	
	if(document.testimonials_frm.heading.value.length==0)
		msg+="Enter Heading!\n";
	
	if(document.testimonials_frm.excerpt.value.length==0)
		msg+="Enter Excerpt!\n";
		
	if(document.testimonials_frm.fulltext.value.length==0)
		msg+="Enter Full Text!\n";
		
	if(document.testimonials_frm.byline.value.length==0)
		msg+="Enter Byline!\n";
		
	if(document.testimonials_frm.location.value.length==0)
		msg+="Enter Location!\n";			
		
	if(msg.length > 0)
	{
		alert(msg);
		return false;
	}
	else
		return	true;
		
}			
