// JavaScript Document

<!--
function GP_AdvOpenWindow(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;  
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth; 
		if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0; 						
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;  
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    	ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    	popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    	popupWindow[wp].document.body.onbeforeunload = function() {
  			if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    		window.onbeforeunload = null;	}  
   		autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  	window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }   
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}
//-->

<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->

function func_popup(obj_file) 
{ 
		popup_win='scrollbars=yes,width=575,height=390,resizeable=yes,top=0,left=0'; 
		window.open(obj_file,"newwindow",popup_win); 
		popop_win.window.focus();
}

function func_is_positive_integer(param_text)
{
	var b_is_positive_integer=true;
	var str_text=new String(func_trim(param_text));
	var i_loop;
	for(i_loop=0;i_loop<str_text.length;i_loop++)
	{
		if(!(str_text.charAt(i_loop)>="0" && str_text.charAt(i_loop)<="9"))
		{
			b_is_positive_integer=false;
			break;
		}
	}
	if(b_is_positive_integer)
	{
		var i_integer=new Number(str_text);
		if(i_integer.valueOf()<=0)
		{
			b_is_positive_integer=false;
		}
	}
	return b_is_positive_integer;
}

function func_trim(param_text)
{
	var str_text=new String(param_text);
	var str_return_text;
	str_return_text="";
	b_non_blank_started=false;
	b_non_blank_ended=false;
	str_intermediate_blank_chunk="";
	var i_loop;
	for(i_loop=0;i_loop<str_text.length;i_loop++)
	{
		if(str_text.charCodeAt(i_loop)!=32)
		{
			if(!b_non_blank_started)
			{
				b_non_blank_started=true;
			}
			if(b_non_blank_started && !b_non_blank_ended)
			{
				str_return_text+=str_text.charAt(i_loop);
			}
			if(b_non_blank_ended)
			{
				str_return_text+=(str_intermediate_blank_chunk+str_text.charAt(i_loop));
				b_non_blank_ended=false;
				str_intermediate_blank_chunk="";
			}
		}
		else
		{
			if(b_non_blank_started)
			{
				b_non_blank_ended=true;
				str_intermediate_blank_chunk+=" ";
			}
		}
	}
	return str_return_text;
}

function func_update_cart()
{
		//for(i_loop=0; i_loop < document.frm_review.elements.length;i_loop++)
		//{
		//	alert(document.frm_review.elements[i_loop].name + ": " + document.frm_review.elements[i_loop].value)
		//}
		
		var obj_form = document.frm_review;
		var b_cor = true;
		for(var i=0; i<document.frm_review.elements.length; i++)
		{
			var str_name = document.frm_review.elements[i].name;
			var str_value = document.frm_review.elements[i].value;
			var obj_element = ("document.frm_review." + str_name);
			var type=document.frm_review.elements[i].type;
			if(type=="text")
			var str_text = eval(obj_element).value
			{
				var i_loop;
				for(i_loop=0;i_loop<str_text.length;i_loop++)
				{
					if(str_text.charCodeAt(i_loop)< 48 || str_text.charCodeAt(i_loop) > 57)
					{ 
						b_cor = false;
					}
				}
				if (str_text <= 0)
				{
					b_cor = false;
				}
			}
			
		}
		if (!(b_cor))
			{
				alert("Enter a valid quantity");
			}
		else
			{
			obj_form.hid_action.value = "update";
			obj_form.action="cart.asp";
			obj_form.method="post";
			obj_form.submit();
			}
	}
	

function func_delete_cart()
	{
		var b_correct=true;
		obj_form = document.frm_review;
		if (b_correct && 	(Validate_CheckBox("Products","chk_items",document.frm_review,true) ))
		{
			if(confirm("Are you sure you want to delete the selected Products(s)?"))
			{
			/////	func_store_selected_checkboxes('frm_review','hid_items_id','chk_items');			
				obj_form.hid_action.value = "delete";
				obj_form.action="cart.asp";
				obj_form.method="post";
				obj_form.submit();
			}
			else
			{
				b_correct = false;
			}
		}
		else
		{
			b_correct = false;
			alert("Please select atleast one product");
		}
		//return b_correct;
	}

	function func_clear_cart()
	{
		if(confirm("It will delete all products."))
		{
			var obj_form = document.frm_review;
			obj_form.hid_action.value = "clear";
			obj_form.action="cart.asp";
			obj_form.method="post";
			obj_form.submit();
		}
	}
	
	function Validate_CheckBox(strLabel,strCheckBoxName,objForm,bChecked)
	{
	var bCorrect=true;
	
	//Check box validation is optional, if bChecked is true then it is checked for Selection.
	if(bCorrect && bChecked)
	{
		if(!IsCheckboxSelected(objForm,strCheckBoxName))
		{
			bCorrect=false;
		}
	}
	return bCorrect;
}

function IsCheckboxSelected(objForm,strName)
{
	var bcorrect=false;
	for(var i=0; i<objForm.elements.length; i++)
	{
		var name=objForm.elements[i].name;
		var type=objForm.elements[i].type;
		if((type=="checkbox") && (name.indexOf(strName)!=-1))
		{
			var val=objForm.elements[i].checked;
			if(val==true)
			{
				bcorrect = true;
				break;
			}
		}
	}
	return bcorrect;
}	

function func_store_selected_checkboxes(str_form_name,str_hidden_name,str_search_chars)
{
	var obj_form=eval("document." + str_form_name);
	var obj_hidden=eval("document." + str_form_name + "." + str_hidden_name);
	var i_length=str_search_chars.length;
	eval("document." + str_form_name + "." + str_hidden_name).value="";
	for(var iLoop=0;iLoop<obj_form.elements.length;iLoop++)
	{
		if(obj_form.elements[iLoop].type=="checkbox")
		{
			var str_checkbox_name=new String(obj_form.elements[iLoop].name);
			if(str_checkbox_name.slice(0,i_length)==str_search_chars)
			{
				if(obj_form.elements[iLoop].checked==true)
				{
					obj_hidden.value+=(obj_hidden.value=="") ? str_checkbox_name.slice(i_length) : ("," + str_checkbox_name.slice(i_length));
				}
			}
		}
	}		
	//alert(obj_hidden.value);
}	

function func_checkout()
{
	var obj_form = document.frm_review;
	obj_form.hid_action.value = "checkout";
	obj_form.action="userdetails.asp";
	obj_form.method="post";
	obj_form.submit();
}
