/* function for opening popup window */

function login_check(aem,avem,alp)
{
	if(document.frm_login.usrname.value=='')
	{
		alert(aem);
		document.frm_login.usrname.focus();
		return false;
	}

	else if(document.frm_login.usrname.value!='')
	{
		if(!validateEmail(document.frm_login.usrname.value))
		{
			alert(avem);
			document.frm_login.usrname.focus();
			return false;
		}	
		
	}
	 if(document.frm_login.pswd.value=='')
	{
		alert(alp);
		document.frm_login.pswd.focus();
		return false;
	}
	return true;
}

function newsletter_check(aem,avem)
{
	if(document.frm_nl.news_email.value=='')
	{
		alert(aem);
		document.frm_nl.news_email.focus();
		return false;
	}

	else if(document.frm_nl.news_email.value!='')
	{
		if(!validateEmail(document.frm_nl.news_email.value))
		{
			alert(avem);
			document.frm_nl.news_email.focus();
			return false;
		}	

	}
	return true;
}
function validateEmail(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function hideSubMenu(id)
{
document.getElementById('submenu_'+id).style.display='none';
}

function openpopup(url,popup_name,height,width,other_properties)
{
	var left		= parseInt((screen.width-621)/2);
	var top			= parseInt((screen.height-410)/2)	
	var win_options = 'height=410,width=621,resizable=yes,' 
	+ 'scrollbars=yes,left=' + left + ',top=' + top;

	mywin=window.open(url,popup_name,win_options);

}
function checkDate(date_value)
{
	//valid format is DD/MM/YYYY
	
	var val_chk_dt = date_value.split("/");
	new_date = new Date(val_chk_dt[2],val_chk_dt[1]-1,val_chk_dt[0], 00, 00, 00);

	if(new_date.getFullYear()!=val_chk_dt[2]||new_date.getDate()!=val_chk_dt[0]||new_date.getMonth()!=val_chk_dt[1]-1){
		alert("Please enter valid date in DD/MM/YYYY format!");
			return false;
	}	
	return true;

}
/// Tool Tips

function doTooltip(e, msg) {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ){ 
	return; 
  }
  Tooltip.show(e, msg);
}
function hideTip() {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.hide();
}

function IsInt(sText)
{
   var ValidChars = "0123456789";
   var IsInt=true;
   var Char;
   var sText1 = sText.value;

   for (i = 0; i < sText1.length && IsInt == true; i++) 
   { 
      Char = sText1.charAt (i ); 
      if (ValidChars.indexOf(Char) == -1) 
      {

		 IsInt = false;
      }
   }

   return IsInt;
}
function validateEmail(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function simplePreload()

{ 

  var args = simplePreload.arguments;

  document.imageArray = new Array(args.length);

  for(var i=0; i<args.length; i++)

  {

    document.imageArray[i] = new Image;

    document.imageArray[i].src = args[i];

  }

}

function addToBacket2()
{

	if(document.getElementById("popcolor").value == "true"){

		if(document.getElementById("colors1").value == ""){
		alert("please select color");
		document.getElementById("colors1").focus();
		return false;
		}

		var color = document.getElementById("colors1").value;
	}

	

	if(document.getElementById("popsize").value == "true"){
		if(document.getElementById("sizes1").value == ""){
		alert("please select size");
		document.getElementById("sizes1").focus();
		return false;
		}
	}
	if(document.getElementById("popsize").value == "true"){
	var size = document.getElementById("sizes1").value;
	}
	var poststr = "prod_id=" + encodeURI( document.getElementById("prod_id_attrib").value ) + "&posted=true" + "&qty="+document.getElementById('qty').value + "&color="+color + "&accessories="+document.getElementById("accessories1").value + "&size="+size;
	makePOSTRequest('/product_attrib_pop.php', poststr,'p_attrib');
	
}


function stateChangedPop()
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
			document.getElementById("txtResultPop").innerHTML=xmlHttp.responseText
		
	}
	else {
		document.getElementById("txtResultPop").innerHTML="";
	}
}



function GetXmlHttpObjectPop(handler)
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}

function GetStockStatusPop()
{

	xmlHttp=GetXmlHttpObjectPop()
	
	var colors ="";
	var sizes ="";
	var qty ="";

	prod_id = document.getElementById("pcid").value;

	obj = document.getElementById("colors1");
	
	if(obj)
	{
		colors = obj[obj.selectedIndex].value;
	}
	
	obj = document.getElementById("sizes1");
	if(obj)
	{
		sizes = obj[obj.selectedIndex].value;
	}
	
	if(sizes && colors == ''){
		url = "/avail_stock.php"+"?";
		url = url+"&pid="+prod_id;
		url = url+"&s="+sizes;
		
		
		qty = document.getElementById('qty').value;
		url = url+"&q="+qty;
		xmlHttp.onreadystatechange=stateChangedPop;
		xmlHttp.open("GET",url,true) ;
		xmlHttp.send(null);
	}
	else if(colors && sizes)
	{
		url = "/avail_stock.php"+"?";
		url = url+"&pid="+prod_id;
		url = url+"&s="+sizes;
		url = url+"&c="+colors;
		
		
		qty = document.getElementById('qty').value;
		url = url+"&q="+qty;
		xmlHttp.onreadystatechange=stateChangedPop;
		xmlHttp.open("GET",url,true) ;
		xmlHttp.send(null);
	}
}
