
function DoNav(xRowId){
	var row = document.getElementById(xRowId);
		if(row.className=='pro_list_box')
		{	
			row.className='pro_list_box_hover';
			row.onmouseout = new Function("this.className='pro_list_box'");		
		}
		else if(row.className=='pro_list_box_alternet')
		{
			row.className='pro_list_box_hover';
			row.onmouseout = new Function("this.className='pro_list_box_alternet'");	
		}
}
function DoNav_table(xRowId){
	var row = document.getElementById(xRowId);
		if(row.className=='table_content')
		{	
			row.className='table_content_hover';
			row.onmouseout = new Function("this.className='table_content'");		
		}
		else if(row.className=='table_content_alternat')
		{
			row.className='table_content_hover';
			row.onmouseout = new Function("this.className='table_content_alternat'");	
		}
}

function validateEmails(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 trim(par)
{
	var y = par.length;
	var ret = '';
	var ex=0;
	var bl=0;
	for (i=0;i<y;i++)
	{
		if (par.charAt(i) == ' ')
			bl = bl+1
		else
		{
			ret=ret+par.charAt(i);
			ex = ex+1
		}
	}
	if (bl==y)
		return true;
	else 
		return false;
	
}

function advance_validations(oform)
{
	var msg="";
	var msg1=SEARCH_ADVANCE_SEARCH_01;
    if(oform.combo_categories.value=="")
	{
		msg += SEARCH_ADVANCE_SEARCH_02;
	}    
	if(oform.combo_categories.value=="" && oform.txt_price_from.value==""  && oform.date_from_years.value=="")
	{
		msg += SEARCH_ADVANCE_SEARCH_03;
	}
	if(isNaN(oform.txt_price_from.value))
	{
	 	msg +=SEARCH_ADVANCE_SEARCH_04;	
	}
	if(isNaN(oform.txt_price_to.value))
	{
		msg +=SEARCH_ADVANCE_SEARCH_05;
	}
	
	if(msg != "")
	{
		msg1 +=msg;
		alert(msg1);
		return false;
	}
	else
	{
		
		return true;
	}

}

function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123)|| (hh==32))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}
function simple_search(oforms)
{
	if(trim(oforms.txtkeywords.value))
	{
		alert(SEARCH_01);
		return false;
	}
}

function login_validations(oform)
{
  var minlength=6;
   var invalid = " "; 

	if(!validateEmails(oform.reg_username.value))
	{
		alert(REGISTRATION_LOG_IN_01);
		oform.reg_username.focus();
		return false;
	}
	if(oform.reg_password.value=="")
	{
		alert(REGISTRATION_LOG_IN_02);
		oform.reg_password.focus();
				return false;
	}
else 
{  
    if (oform.reg_password.value.length < minlength) 
	{
			alert(REGISTRATION_LOG_IN_03);
			oform.reg_password.focus();
					return false;
	}
else if (oform.reg_password.value.indexOf(invalid) > -1) 
	{
		alert(REGISTRATION_LOG_IN_04);
		oform.reg_password.focus();
				return false;
	}	

}
		return true;
}
  
   
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
//end - Function user for generating AJAX Object



function submit_login(ofrm)
{ 
	var emailRegxp = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/;
	if(ofrm.txtusername.value=="")
	{
		alert(REGISTRATION_LOGIN_01);
		ofrm.txtusername.focus();
		return false;
	}
	else if(emailRegxp.test(ofrm.txtusername.value)!=true)
	{
		alert(REGISTRATION_LOGIN_02);
		ofrm.txtusername.focus();
		return false;
	}
	if(ofrm.txtpassword.value=="")
	{
		alert(REGISTRATION_LOGIN_03)
		ofrm.txtpassword.focus();
		return false;
	}
	else if(ofrm.txtpassword.value.length<6)
	{
		alert(REGISTRATION_LOGIN_04);
		return false;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		alert (REGISTRATION_LOGIN_05);
  		return false;
  	}
	var url="modules/registration/action/login.php";
	
	url=url+"?username="+ofrm.txtusername.value;
	url=url+"&password="+ofrm.txtpassword.value;
	
	if(ofrm.web_remember_me.checked == true)
		url=url+"&rem=yes";	
	else
		url=url+"&rem=no";
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged_login;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	return false;
}

function stateChanged_login()
{
	if (xmlHttp.readyState==4)
	{
		if(xmlHttp.responseText == 1)
		{
			alert("You have successfully logged in!");
			document.location.href ='?goal=my_account';
		}
		else 
			alert("Username / Password incorrect. Please try again!");
		
	}
}

function validations_registration(oform)
{
		var msg="";
		var msg1=REGISTRATION_NEW_REGISTRATION_01;
	if(!validateEmails(oform.txtusername.value))
	{
		msg += REGISTRATION_NEW_REGISTRATION_02;
	}
	
	var invalid = " "; 
	var minLength = 6; 
	var pw1 = oform.txtpassword.value;
	var pw2 = oform.txtconfirmpassword.value;

	if (pw1 == '' && pw2 == '') 
	{
			msg += REGISTRATION_NEW_REGISTRATION_03;
	
	}

	else if (oform.txtpassword.value.length < minLength) 
	{
			msg += REGISTRATION_NEW_REGISTRATION_04 + " "+ minLength +  " "+REGISTRATION_NEW_REGISTRATION_05;
	
	}
	
	else 
	{
		if (pw1 != pw2) 
		{
			msg +=REGISTRATION_NEW_REGISTRATION_06;
		}
		// check for spaces
	if (oform.txtpassword.value.indexOf(invalid) > -1) 
	{
		msg += REGISTRATION_NEW_REGISTRATION_07;

	}
   }
   
	if(oform.txtfirstname.value=="")
	{
		msg += REGISTRATION_NEW_REGISTRATION_08;
	}
	else if(trim(oform.txtfirstname.value))
	{
		msg +=REGISTRATION_NEW_REGISTRATION_09;
	}
      if(oform.txtlastname.value=="")
   {
		msg += REGISTRATION_NEW_REGISTRATION_10;
   }
	else if(trim(oform.txtlastname.value))
	{
		msg +=REGISTRATION_NEW_REGISTRATION_11;
	}	
  
   if(oform.txtstreetaddress.value=="")
    {
		msg += REGISTRATION_NEW_REGISTRATION_12;
    }
	
	else if(trim(oform.txtstreetaddress.value))
	{
		msg += REGISTRATION_NEW_REGISTRATION_13;
	}
   if(oform.txtcity.value=="")
    {
		msg +=REGISTRATION_NEW_REGISTRATION_14;
    }
	else if(trim(oform.txtcity.value))
	{
		msg += REGISTRATION_NEW_REGISTRATION_15;
	}
	
	
	if(oform.cmb_country.value=="")
    {
		msg += REGISTRATION_NEW_REGISTRATION_16;
    }
	
	if(oform.txtpostalcode.value=="")
    {
		msg += REGISTRATION_NEW_REGISTRATION_17;
    }

	
	if(oform.txtphone.value=="")
    {
		msg+= REGISTRATION_NEW_REGISTRATION_18;
    }
	else if(trim(oform.txtphone.value))
	{
		msg += REGISTRATION_NEW_REGISTRATION_19
	}
	else if(oform.txtphone.value<0 || oform.txtphone.value.length<5)
	{
		msg +=REGISTRATION_NEW_REGISTRATION_19;
	}
	
	if(msg != "")
	{
		msg1 +=msg;
		alert(msg1);
		return false;
	}
	else
	{
		return true;
	}

}
function valid_forgotpassword(oform)
{
	if(!validateEmails(oform.txtusername.value))
	{
		alert(REGISTRATION_FORGET_PASSWORD_01);
		oform.txtusername.focus();
		return false;
	}
}
function validation_changepassword(oform)
{

		var msg="";
		var msg1= MY_ACCOUNT_CHANGE_PASSWORD_01;
		var invalid = " ";
	var minLength = 6;
	var pw1 = oform.new_pass.value;
	var pw2 = oform.confirm_pass.value;
	
	if (oform.old_pass.value=='') 
	{
		msg += MY_ACCOUNT_CHANGE_PASSWORD_02;

	}
    if (oform.new_pass.value=='') 
	{
		msg += MY_ACCOUNT_CHANGE_PASSWORD_03;

	}
	else if (oform.new_pass.value.length < minLength) 
	{
			msg += MY_ACCOUNT_CHANGE_PASSWORD_04 + minLength + MY_ACCOUNT_CHANGE_PASSWORD_05;
	
	}
	if (oform.confirm_pass.value=='') 
	{
		msg += MY_ACCOUNT_CHANGE_PASSWORD_06;

	}
	else 
	{
		if (pw1 != pw2) 
		{
			msg += MY_ACCOUNT_CHANGE_PASSWORD_07;
		}
		// check for spaces
		if (oform.new_pass.value.indexOf(invalid) > -1) 
		{
			msg += MY_ACCOUNT_CHANGE_PASSWORD_8;
	
		}
 	}
   
   
   if(msg != "")
	{
		msg1 +=msg;
		alert(msg1);
		return false;
	}
	else
	{
		return true;
	}
   
}
function validation_profile(oform)
{
	
		var msg="";
		var msg1= MY_ACCOUNT_MYPROFILE_01;
		
	/*if(!validateEmails(oform.txtusername.value))
	{
		msg += "* Valid User Name\n";
	}*/
	
	
   
	if(oform.f_name.value=="")
	{
		msg += MY_ACCOUNT_MYPROFILE_02;
	}
	else if(trim(oform.f_name.value))
	{
		msg += MY_ACCOUNT_MYPROFILE_03;
	}
      if(oform.l_name.value=="")
   	{
		msg += MY_ACCOUNT_MYPROFILE_04;
	}
	else if(trim(oform.l_name.value))
	{
		msg += MY_ACCOUNT_MYPROFILE_05;
	}	
	
	/*if(oform.start_days.value=="" || oform.start_months.value=="" || oform.start_years.value=="")
	{
		msg +="* Date of birth\n";
	}*/

   if(oform.street_address.value=="")
    {
		msg += MY_ACCOUNT_MYPROFILE_06;
    }
	
	else if(trim(oform.street_address.value))
	{
		msg += MY_ACCOUNT_MYPROFILE_07;
	}
	 
   if(oform.city.value=="")
    {
		msg += MY_ACCOUNT_MYPROFILE_08;
    }
	else if(trim(oform.city.value))
	{
		msg += MY_ACCOUNT_MYPROFILE_09;
	}
	
	
	if(oform.country.value=="")
    {
		msg += MY_ACCOUNT_MYPROFILE_10;
    }
	if(oform.country.value=="")
    {
		msg += MY_ACCOUNT_MYPROFILE_10;
    }
	if(trim(oform.post_code.value))
    {
		msg += MY_ACCOUNT_MYPROFILE_13;
    }
	
	else if(isNaN(oform.post_code.value))
    {
		msg += MY_ACCOUNT_MYPROFILE_13;
    }
	
	if(oform.phone.value=="")
    {
		msg+= MY_ACCOUNT_MYPROFILE_11;
    }
	else if(trim(oform.phone.value))
	{
		msg += MY_ACCOUNT_MYPROFILE_12;
	}
	else if(oform.phone.value<0 || oform.phone.value.length<5)
	{
		msg += MY_ACCOUNT_MYPROFILE_12;
	}

	if(msg != "")
	{
		msg1 +=msg;
		alert(msg1);
		return false;
	}
	else
	{
		return true;
	}

}

function EditRecord(oforms)
{
	var flag = false;
	var msg ='';
	
	for (var i=0;i<oforms.elements.length;i++)
	{		
		for(var s=0;s<=i;s++)
		{
			if(oforms.elements[i].name =='qty'+s)		
			{				
				var requirQuantiy = oforms.elements[i].value;
				var availableQuantity = eval("document.cartforms.pqty"+s+".value");
				
				if(parseInt(availableQuantity) < parseInt(requirQuantiy))
				{
					if(CART_08=='en')
						msg += CART_06+availableQuantity+CART_07+eval("document.cartforms.pname"+s+".value")+'\n';
					else if(CART_08=='de')
						msg += CART_06+eval("document.cartforms.pname"+s+".value")+CART_07+eval("document.cartforms.pqty"+s+".value")+'\n';
					
					flag = true;
				}
			}
		}
	}
					
	if(flag)
	{
		alert(msg);	
		return false;
	}
	if(not_null(oforms)==false)
	{
		alert(CART_01);
		return false;
	}	
	else
	{
		oforms.action = "index.php?goal=cart";
		oforms.submit();
	}				
}
/****************************** End - Edit record ********************************/
function not_null(oform)
{
	var j=0;
	var statuss=false;
	for (var i=0;i<oform.elements.length;i++)
	{
		
		for(var s=0;s<=i;s++)
		{
			if(oform.elements[i].name =='qty'+s)		
			{
					var e = oform.elements[i];
					if(isNaN(e.value)||(trim(e.value))||(e.value<=0))
					statuss = true;
					{j++;}
			}

		}
		
	}
		if(statuss==true)
		{
		
			return false;
		}
		else
		{
			return true;
		}
}

/****************************** Start - deleting single record ********************************/
function DeleteRecord(oforms)
{
	var selectvalues = getCheckValue('ch[]');
	if(selectvalues == "")
	{
		alert(CART_02);
		return false;
	}
	else
	{
	var blcConfirm;
	blcConfirm=confirm(CART_03);
		if (blcConfirm == true)
		{
		
			oforms.action = "?goal=cart&mode=cartdelete";
			oforms.submit();		
		}
	
	}
}
/****************************** End - deleting single record ********************************/



/********************************** Start - Select all checkbox **********************************/
function selectall(oform)
{
	for (var i=0;i<oform.elements.length;i++)
    {
      var e = oform.elements[i];
      var boolValue = oform.checkall.checked;
      if (e.name != 'checkall')
	  {
        e.checked = boolValue;
	  }
    }
}
/********************************** End - Select all checkbox **********************************/


/********************************** Start - get checked value **********************************/
Array.prototype.append = function (val) 
{
	this[this.length] = val;
}

function getFormGroup(name) 
{
	return document.getElementsByName(name);
}

function isChecked(name) 
{
	elements = getFormGroup(name);
	if (elements)
	/* loop over all the checkboxes */
		for (i = 0; i < elements.length; i++)
			if (elements[i].checked)
				return true;
			/* either not found or none are checked */
	return false;
}


/* return an array of checked elements */
function getCheck(name) 
{
	elements = getFormGroup(name);
	checked = new Array();
	if (elements)
		for (i = 0; i < elements.length; i++)
			if (elements[i].checked)
			/* use our new array function */
				checked.append(elements[i]);
			/* return the array, it may be empty */
	return checked;
}


/* return an array of the checked elements' values */
function getCheckValue(name) 
{
	elements = getCheck(name);
	values = new Array();
	if (elements)
		for (i = 0; i < elements.length; i++)
			values.append(elements[i].value);
			return values;
}
function validations_cart(oform)
{
	var status = false;
	for (var i=0;i<oform.elements.length;i++)
    {
		  var e = oform.elements[i];
		  if (e.name == 'pqty0')
		  {	
				 status = true;
		  }
    }
	
	if(!status)
	{
		alert(CART_04);
		return false;
	}
	else if(not_null(oform)==false)
	{
		alert(CART_05);
		return false;
		
	}
	else
	{
		oform.action="index.php?goal=checkout";
		oform.submit();
	}
}
function round1(val)
{
	var v = Math.round(val*100)/100;
	var a;
	if(!test1(v))
	{
		a =  v;		
	}
	else
	{
		a = v +'.00';
	}	
	return a;
}
function test1(str) 
{
     return /^ *[0-9]+ *$/.test(str);
}

function gotorevert(path)
{
	document.cartforms.action=path;
	document.cartforms.submit();
}
function chkbs(oform)
{
	if(oform.information.checked==true)
	{
		oform.shipping_firstname.value=oform.billing_firstname.value;
		oform.shipping_lastname.value=oform.billing_lastname.value;
		oform.shipping_companyname.value=oform.billing_companyname.value;
		oform.shipping_streetaddress.value=oform.billing_streetaddress.value;
		oform.shipping_address2.value=oform.billing_address2.value;
		oform.shipping_city.value=oform.billing_city.value;
		oform.shipping_state.value=oform.billing_state.value;
		oform.shipping_country.value=oform.billing_country.value;
		oform.shipping_postalcode.value=oform.billing_postalcode.value;
	}
}
function validations_checkout(oform)
{
	var msg="";
	var msg1=CHECKOUT_01;
		
	if(oform.billing_firstname.value=="")
		msg+=CHECKOUT_02;
	else if(trim(oform.billing_firstname.value))
		msg +=CHECKOUT_03;
	if(trim(oform.billing_lastname.value))
		msg +=CHECKOUT_18;

	if(oform.billing_streetaddress.value=="")
		msg+=CHECKOUT_04;
	else if(trim(oform.billing_streetaddress.value))
		msg +=CHECKOUT_05;
	if(oform.billing_city.value=="")
		msg+=CHECKOUT_06;
	else if(trim(oform.billing_city.value))
		msg +=CHECKOUT_07;

	if(oform.billing_country.value=="")
		msg+=CHECKOUT_08;
	if(oform.billing_postalcode.value=="")
		msg+=CHECKOUT_09;

	//*************shipping information*************//
	if(oform.shipping_firstname.value=="")
		msg+=CHECKOUT_10;
	else if(trim(oform.shipping_firstname.value))
		msg +=CHECKOUT_11;
	if(trim(oform.shipping_lastname.value))
		msg +=CHECKOUT_19;

	if(oform.shipping_streetaddress.value=="")
		msg+=CHECKOUT_12;
	else if(trim(oform.shipping_streetaddress.value))
		msg +=CHECKOUT_13;
	if(oform.shipping_city.value=="")
		msg+=CHECKOUT_14;
	else if(trim(oform.shipping_city.value))
		msg +=CHECKOUT_15;
	if(oform.shipping_country.value=="")
		msg+=CHECKOUT_16;
	if(oform.shipping_postalcode.value=="")
		msg+=CHECKOUT_17;
	
	if(msg!="")
	{
		msg1 += msg;
		alert(msg1);
		return false;
	}
	else
	{
		oform.action="?goal=checkout&mode=payment";
		oform.submit();
	}
}
function goback(page)
	{
		document.location.href="?goal=checkout&mode=checkout";
	}
	

var newwin;
function openpopup(url,w,h){
	if(newwin)
		newwin.close();
	var width = w;
	var height = h;
	var left = (screen.width - width)/2;
	var top = (screen.height - height)/2;
	var params = 'width='+width+', height='+height;
	params += ', top='+top+', left='+left;
	params += ', directories=no';
	params += ', location=no';
	params += ', menubar=no';
	params += ', resizable=no';
	params += ', scrollbars=yes';
	params += ', status=no';
	params += ', toolbar=no';
	newwin=window.open(url,'Cha1', params);
	if (window.focus) {newwin.focus()}
	return false;
}


function hide(d)
{
  if(document.getElementById(d).style.display=="none")
  {
		document.getElementById(d).style.display="block"
  }
 else 
  {
	    document.getElementById(d).style.display="none"
  } 
}


function adjust_middle()
{
	var height=window.innerHeight;//Firefox
	if (document.body.clientHeight)
	{
		height=document.body.clientHeight;//IE
	}
	var xMiddle = document.getElementById("adjustMiddle").style.height;
	var xInt = parseInt(xMiddle.substring(0,3));

	var adJheight = (height - xInt)/2 + "px";
		document.getElementById("adjustMiddle").style.top = adJheight;
	}
	
	
function adjust_height()
{
	var height=window.innerHeight;//Firefox
	if (document.body.clientHeight)
	{
		height=document.body.clientHeight;//IE
	}
	var adjheight = (height - 284) + "px";
	var xWall = document.getElementById("wall").style.height;
	var xheight = parseInt(xWall.substring(0,3));
	var xtotal = xheight+284;
	if (height > xtotal){
		document.getElementById("wall").style.height = adjheight;
		document.getElementById("wrapper").style.height = height+"px";
	}
	else{
	document.getElementById("wall").style.height = xWall;
	}
}

