function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) { 
var i, j; 
var prompt; // empty existing items 
for (i = selectCtrl.options.length; i >= 0; i--) { 
selectCtrl.options[i] = null; 
} 
prompt = (itemArray != null) ? goodPrompt : badPrompt; 
if (prompt == null) { 
j = 0; 
} 
else { 
selectCtrl.options[0] = new Option(prompt); 
j = 1; 
} 
if (itemArray != null) { // add new items 
for (i = 0; i < itemArray.length; i++) { 
selectCtrl.options[j] = new Option(itemArray[i][0]); 
if (itemArray[i][1] != null) { 
selectCtrl.options[j].value = itemArray[i][1]; 
} 
j++; 
} // select first item (prompt) for sub list 
selectCtrl.options[0].selected = true; 
  } 
} //  End --> 

function SetSellType(p_num_product_index,p_num_group_index,p_obj_sell_type) { 
  p_obj_sell_type.value = arr_product[p_num_group_index] [p_num_product_index] [2];
}

function MagnifyImg_2(p_obj_name)
{
 var num_product_index = p_obj_name.selectedIndex;
 if ((num_product_index == -1)||(num_product_index == 0))
 	return;
 var str_product_code = p_obj_name.options[num_product_index].value;
 var num_width = 330;
 var num_height = 230;
 var num_top = 100;		
 var num_left = 100;
 var str_url = 'common/magnifier.asp?p1='+str_product_code.replace(" ","");
 var str_caption	= str_product_code.replace(" ","");
 var win_magnify = window.open(str_url,str_caption,"width=" + num_width + ",height=" + num_height  + ",resizable=no,status=no,scrollbars=no,top= " + num_top + ",left=" + num_left) ;
 win_magnify.focus(); }

function MagnifyImg(p_str_img_name)
{var num_width = 330;
 var num_height = 230;
 var num_top = 100;		
 var num_left = 100;
 var str_url = 'common/magnifier.asp?p1='+p_str_img_name;
 var str_caption	= p_str_img_name;
 var win_magnify = window.open(str_url,str_caption,"width=" + num_width + ",height=" + num_height  + ",resizable=no,status=no,scrollbars=no,top= " + num_top + ",left=" + num_left) ;
 win_magnify.focus(); }
 
function ShowOrderForm(p_num_language_isn)
{var num_width = 600;
 var num_height = 610;
 var num_top = 10;		
 var num_left = 10;
 if (p_num_language_isn == 1)
	 { var str_url = 'order.asp?p0=1';
	   var str_caption	= 'SIPARIS';}
 else	 
 	 {var str_url = 'order.asp?p0=2';
	  var str_caption= 'ORDER';}	 	 

 var win_magnify = window.open(str_url,str_caption,"width=" + num_width + ",height=" + num_height  + ",resizable=no,status=no,scrollbars=no,top= " + num_top + ",left=" + num_left) ;
 win_magnify.focus(); }
 

function check_is_numeric(p_str_value)
{   
  if (p_str_value.length > 0)
  {   for (i = 0;  i < p_str_value.length;  i++)
	  { ch = p_str_value.charAt(i);
		if ((ch != '0')&&(ch != '1')&&(ch != '2')&&(ch != '3')&&(ch != '4')&&(ch != '5')&&(ch != '6')&&(ch != '7')&&(ch != '8')&&(ch != '9'))
		{return false;}
	  }
    }
	return true;
}

function check_email(p_obj,p_num_language_isn) 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(p_obj.value))
	{
		return true
	}
	
	if (p_num_language_isn==1)
	{	str_msg = 'Gecersiz E-Posta Adresi...!';
	}	
	if (p_num_language_isn==2)
	{	str_msg = 'Invalid E-mail Address...!';
	}
	alert(str_msg);
    p_obj.focus();
	return false;	
}


function validate_product(p_cmb_product,p_txt_quantity,p_num_language_isn)
{
	var str_msg_empty = '';
	var str_msg_not_numeric = '';	

	if (p_num_language_isn==1)
	{	str_msg_empty = 'Adet giriniz...!';
		str_msg_not_numeric = 'Adet numerik olmali...!';
	}	
	if (p_num_language_isn==2)
	{	str_msg_empty = 'Quantity must be entered...!';
		str_msg_not_numeric = 'Quantity should be numeric...!';
	}

	var num_selected_ind = p_cmb_product.selectedIndex; 
	if (num_selected_ind > 0)
	{  
		if (p_txt_quantity.value.length <= 0)
   		{  	alert(str_msg_empty);
      		p_txt_quantity.focus();
			return false;			
   		}
		if (check_is_numeric(p_txt_quantity.value)== false)
   		{  alert(str_msg_not_numeric);
      		p_txt_quantity.focus();
			return false;
   		}
	}
	return true;
}

function check_is_empty(p_obj,p_str_eng_name,p_str_tr_name,p_num_language_isn)
{   
  if (p_obj.value.length <= 0)
	{   
	    if (p_num_language_isn==1)	alert('Lütfen "'+p_str_tr_name+'" sahasini doldurunuz...!');
	    if (p_num_language_isn==2)	alert('Please fill field "'+p_str_eng_name+'" ...!');
   		p_obj.focus();
		return false;
	}
  return true;
}



function check_from(p_num_language_isn)
{
	if (validate_product(frm_main.cmb_product_1,frm_main.txt_quantity_1,p_num_language_isn)==false) return false;
	if (validate_product(frm_main.cmb_product_2,frm_main.txt_quantity_2,p_num_language_isn)==false) return false;
	if (validate_product(frm_main.cmb_product_3,frm_main.txt_quantity_3,p_num_language_isn)==false) return false;
	if (validate_product(frm_main.cmb_product_4,frm_main.txt_quantity_4,p_num_language_isn)==false) return false;
	if (validate_product(frm_main.cmb_product_5,frm_main.txt_quantity_5,p_num_language_isn)==false) return false;
	if (validate_product(frm_main.cmb_product_6,frm_main.txt_quantity_6,p_num_language_isn)==false) return false;
	if (validate_product(frm_main.cmb_product_7,frm_main.txt_quantity_7,p_num_language_isn)==false) return false;
	if (validate_product(frm_main.cmb_product_8,frm_main.txt_quantity_8,p_num_language_isn)==false) return false;	
	if (validate_product(frm_main.cmb_product_9,frm_main.txt_quantity_9,p_num_language_isn)==false) return false;						
	if (validate_product(frm_main.cmb_product_10,frm_main.txt_quantity_10,p_num_language_isn)==false) return false;
	if (validate_product(frm_main.cmb_product_11,frm_main.txt_quantity_11,p_num_language_isn)==false) return false;
	if (validate_product(frm_main.cmb_product_12,frm_main.txt_quantity_12,p_num_language_isn)==false) return false;
	if (validate_product(frm_main.cmb_product_13,frm_main.txt_quantity_13,p_num_language_isn)==false) return false;
	if (validate_product(frm_main.cmb_product_14,frm_main.txt_quantity_14,p_num_language_isn)==false) return false;	
	if (validate_product(frm_main.cmb_product_15,frm_main.txt_quantity_15,p_num_language_isn)==false) return false;						

	if (frm_main.cmb_product_1.selectedIndex <= 0)
		if (frm_main.cmb_product_2.selectedIndex <= 0)
			if (frm_main.cmb_product_3.selectedIndex <= 0)
				if (frm_main.cmb_product_4.selectedIndex <= 0)
					if (frm_main.cmb_product_5.selectedIndex <= 0)
						if (frm_main.cmb_product_6.selectedIndex <= 0) 
							if (frm_main.cmb_product_7.selectedIndex <= 0)
								if (frm_main.cmb_product_8.selectedIndex <= 0)
									if (frm_main.cmb_product_9.selectedIndex <= 0)
										if (frm_main.cmb_product_10.selectedIndex <= 0)
											if (frm_main.cmb_product_11.selectedIndex <= 0)
												if (frm_main.cmb_product_12.selectedIndex <= 0)
													if (frm_main.cmb_product_13.selectedIndex <= 0)
														if (frm_main.cmb_product_14.selectedIndex <= 0)
															if (frm_main.cmb_product_15.selectedIndex <= 0)
															{	if (p_num_language_isn==1)	alert('Siparis için en az bir ürün secilmeli...!');
																if (p_num_language_isn==2)	alert('At least one product should be selected...!');
																frm_main.cmb_product_1.focus();
																return false;
															}
	if (check_is_empty(frm_main.txt_name,'NAME','AD',p_num_language_isn)== false) return false;
	if (check_is_empty(frm_main.txt_email,'E-MAIL','E-POSTA',p_num_language_isn)== false) return false;	
	if (check_email(frm_main.txt_email,p_num_language_isn)==false) return false;
	if (check_is_empty(frm_main.txt_phone,'TELEPHONE','TELEFON',p_num_language_isn)== false) return false;
	if (check_is_empty(frm_main.txt_address,'ADDRESS','ADRES',p_num_language_isn)== false) return false;	
}

