

function openw(linki,Wwidth,Wheight)
{
	var Pwidth=screen.width/2-parseInt(Wwidth)/2;
	var Pheight=screen.height/2-parseInt(Wheight)/2;
	x=window.open(linki,"window","width="+Wwidth+",height="+Wheight+",scrollbars,top="+Pheight+",left="+Pwidth);
	x.focus();
}
function showPants(num,design){
	openw("big.asp?pants="+num+"&design="+design,610,550);
}

function buy(pants,design,psize){

	var c_k_xl = "73,74,79,60,59,71,78,22,21,28,16,20,10,39,40,12,46,";
	var c_k_l = "10,16,20,21,22,28,46,73,76,79,";
	var c_k_m = "05,10,16,20,21,22,28,46,73,76,";
	var c_xxl = "28,73,74,79,76,20,39,40,21,30,59,12,16,05,10,46,";
	
	var pants_a = new Array("01","04","05","07","10","11","12","16","18","19","20","21","22","24","27","28","29","31","33","39","40","43","46","48","59","60","61","62","63","68","69","71","72","73","74","75","76","78","79","09");
	
	var t_size,is_pants_size;

	is_pants_size = false;

	/**
	if(parseInt(pants)<10){
		t_pants = "0"+pants+",";
	}
	else{
		t_pants = pants+",";
	}
	*/
	t_pants = pants_a[pants-1]+","

		
		
	switch(parseInt(psize)){
		case 1:
			if(c_k_m.indexOf(t_pants)!=-1){
				is_pants_size=true;
			}
			break;
		case 2:
			if(c_k_l.indexOf(t_pants)!=-1){
				is_pants_size=true;
			}
			break;	
		case 3:
			if(c_k_xl.indexOf(t_pants)!=-1){
				is_pants_size=true;
			}
			break;					
		case 4:
			is_pants_size=true;
			break;			
		case 5:
			if(c_xxl.indexOf(t_pants)!=-1){
				is_pants_size=true;
			}
			break;			
	}
	


	if(is_pants_size){
		openw("cart/index.asp?mod=cart&action=add&pants="+pants+"&design="+design+"&size="+psize,700,600);
	}
	else{
		alert("We're sorry, but we don't have the color of pants you've chosen in the selected pants size.\n                     please choose a different color or a diffrerent size");
	}
}

function delItem(id){

	location = "index.asp?mod=cart&action=delete&id="+id;
}

function errorM(num){
	var msg;
	switch(num){
		case 0:
			msg = "Please click on a pants to choose it";
			break;
		case 1:
			msg = "Please click on a desgin to choose it";
			break;
		case 2:
			msg = "Please choose size for your pants (Regular is the one-size)";
			break;		
	}
	alert(msg);
}

function goGallery(){
	openw("gallery.htm",700,610);
}

function goHow(){
	openw("help/help.htm",700,610);
}





function IsNumeric(strString)
   //  check for valid numeric strings	
{
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}


function calcTotal(is_design){
	if(IsNumeric(document.formi.quan.value)){
	 	calcShip();
	 	var sizes
	 	if(is_design){
	 		sizes=new Array(20,25,25,35);
	 	}
	 	else{
			sizes=new Array(15,20,20,30);
		}
		
		document.formi.total.value="$"+(parseInt(document.formi.quan.value)*(sizes[parseInt(document.formi.psize.value)])+parseInt(document.formi.shipping.value.substr(1)))+".00";
	}
	else{
		alert("Quantity must be in numbers");
	}
}

function calcShip(){
	var ind
	if(document.formi.quan.value==1){
		ind = 5;
	}
	else{
		ind = parseInt(document.formi.quan.value)+5;
	}
	document.formi.shipping.value="$"+(ind)+".00";
}

function checkForm(){
	if(document.formi.name.value==""){
		alert("Please fill in your name");
		document.formi.name.focus();
	}
	else{
		if(!isValidEmail(document.formi.email.value)){
			alert("Please fill in your valid email");
			document.formi.email.focus();
		}
		else{
			if(document.formi.phone.value==""){
				alert("Please fill in your phone number");
				document.formi.phone.focus();
			}
			else{
				document.formi.phone1.value="1";
				document.formi.submit();
			}			
		}		
	}
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 
}

