
function setCurrency(TheForm)
{
	TheForm.submit();
}

function createAjax() 
{
	var ajax = false;
	if(window.XMLHttpRequest) 
	{
		ajax = new XMLHttpRequest();
	} 
	else if(window.ActiveXObject) 
	{
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return ajax;
}

function addToCart(product_id, path)
{
	var Input_Id = "quantity_"+product_id;
	var Input_value = parseInt(document.getElementById(Input_Id).value);
	var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	if(isNaN(Input_value) || Input_value <= 0)
	{
		alert("Please Enter Minimum 1 Numeric Quantity");
		document.getElementById(Input_Id).focus();
	}
	else
	{
		var parameters = "shopping_cart=shopping_cart&add2cart="+product_id+"&product_quantity="+Input_value;
		
		var xmlhttp = createAjax();
		
		xmlhttp.onreadystatechange=function()
				  {
				  				
				  if (xmlhttp.readyState==4 && xmlhttp.status==200)
					{
						document.getElementById("mini_cart").innerHTML= xmlhttp.responseText ;
					}
				  }		
				
				xmlhttp.open("POST",path+"shopping_cart.php",true);
				xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				xmlhttp.setRequestHeader("Content-length", parameters.length);
				xmlhttp.setRequestHeader("Connection", "close");
				xmlhttp.send(parameters);
		
		}
}

function ClearCart(path)
{
		var parameters = "shopping_cart=shopping_cart&clear_cart=clear_cart";
		
		var xmlhttp = createAjax();
		
		xmlhttp.onreadystatechange=function()
				  {
				  				
				  if (xmlhttp.readyState==4 && xmlhttp.status==200)
					{
						document.getElementById("mini_cart").innerHTML= xmlhttp.responseText ;
					}
				  }		
				
				xmlhttp.open("POST",path+"shopping_cart.php",true);
				xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				xmlhttp.setRequestHeader("Content-length", parameters.length);
				xmlhttp.setRequestHeader("Connection", "close");
				xmlhttp.send(parameters);

}

function RemoveFromCart(product_id, path)
{
		var parameters = "shopping_cart=shopping_cart&remove_cart="+product_id;
		
		var xmlhttp = createAjax();
		
		xmlhttp.onreadystatechange=function()
				  {
				  				
				  if (xmlhttp.readyState==4 && xmlhttp.status==200)
					{
						document.getElementById("mini_cart").innerHTML= xmlhttp.responseText ;
					}
				  }		
				
				xmlhttp.open("POST",path+"shopping_cart.php",true);
				xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				xmlhttp.setRequestHeader("Content-length", parameters.length);
				xmlhttp.setRequestHeader("Connection", "close");
				xmlhttp.send(parameters);

}

function setCookie(szName, szValue, szExpires)
{
 	var szCookieText = 	   escape(szName) + '=' + escape(szValue);
	
	if (szExpires) {
		var date = new Date();
		date.setTime(date.getTime()+(szExpires*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	
	
	szCookieText +=	 	   (szExpires ? '; EXPIRES=' + expires : '');
	document.cookie = szCookieText;
}


function getCookie(szName)
{
 	var szValue =	  null;
	if(document.cookie)	   //only if exists
	{
       	var arr = 		  document.cookie.split((escape(szName) + '=')); 
       	if(2 <= arr.length)
       	{
           	var arr2 = 	   arr[1].split(';');
       		szValue  = 	   unescape(arr2[0]);
       	}
	}
	return szValue;
}

function deleteCookie(szName)
{
 	var tmp = 	  			 	 getCookie(szName);
	if(tmp) 
	{ setCookie(szName,tmp,(new Date(1))); }
}

function dynamiccontentNS6(elementid,content){
if (document.getElementById && !document.all){
rng = document.createRange();
el = document.getElementById(elementid);
rng.setStartBefore(el);
htmlFrag = rng.createContextualFragment(content);
while (el.hasChildNodes())
el.removeChild(el.lastChild);
el.appendChild(htmlFrag);
}
}


function selectSubCategory(thisValue, path)
{
	
	if(thisValue > 0)
	{
	var parameters = "parent_id="+thisValue;
		
		var xmlhttp = createAjax();

		xmlhttp.onreadystatechange=function()
				  {
				  				
				  if (xmlhttp.readyState==4 && xmlhttp.status==200)
					{
						if(xmlhttp.responseText != "")
						{
							document.getElementById('sub_category').disabled = false;
							document.getElementById('sub_category').innerHTML = xmlhttp.responseText;
							
						}
					}
				  }	
			
		xmlhttp.open("POST",path+"search.php",true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", parameters.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.send(parameters);
	}
	else
	{
		document.getElementById('sub_category').selectedIndex = "0";
		document.getElementById('sub_category').disabled = true;
		document.getElementById('inner_category').selectedIndex = "0";
		document.getElementById('inner_category').disabled = true;
	}

				
}

function selectInnerCategory(thisValue, path)
{
	
	var parameters = "p_id="+thisValue;
		
		var xmlhttp = createAjax();

		xmlhttp.onreadystatechange=function()
				  {
				  				
				  if (xmlhttp.readyState==4 && xmlhttp.status==200)
					{
						if(xmlhttp.responseText != "")
						{
							document.getElementById('inner_category').disabled = false;
							document.getElementById('inner_category').innerHTML = xmlhttp.responseText;
						}
						else
						{
		
							document.getElementById('inner_category').disabled = true;
						}
					}
					
				  }	
			
		xmlhttp.open("POST",path+"search.php",true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", parameters.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.send(parameters);
			
}

function validatesubscribe_email(email)
{
    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 subscribe_email(path)
{
		thevalue = document.getElementById('subscribe_input_mail').value;
		if(validatesubscribe_email(thevalue))
		{
		var parameters = "mail_id="+thevalue;
		
		var xmlhttp = createAjax();

		xmlhttp.onreadystatechange=function()
				  {
				  if (xmlhttp.readyState==1)
				  {
					  document.getElementById('loading').style.display = "block";
				  }
				  
				  if (xmlhttp.readyState==4 && xmlhttp.status==200)
					{
						document.getElementById('loading').style.display = "none";					
						if(xmlhttp.responseText == true)
						{
							alert('Thank You For Subscription!! ');	
						}
						else
						alert('Please Try Again!!');	
					}
					
				  }	
			
		xmlhttp.open("POST",path+"subscribe.php",true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", parameters.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.send(parameters);
		}
		else
		alert('Please Enter Valid Email Id');
}

function sendInquery(theForm, path)
{
	var user_name = theForm.name.value;
	var user_email = theForm.email.value;
	var user_phone = theForm.telephone.value;
	var user_message = theForm.message.value;
	var product_id = theForm.product_id.value;
	
	var parameters = "name="+user_name+"&email="+user_email+"&telephone="+user_phone+"&message="+user_message+"&product_id="+product_id;
		
		var xmlhttp = createAjax();
		
		xmlhttp.onreadystatechange=function()
				  {
				  
				  if (xmlhttp.readyState==1)
				  {
					  document.getElementById('lod').style.display = "block";
				  }
				  
				  if (xmlhttp.readyState==4 && xmlhttp.status==200)
					{
						document.getElementById('lod').style.display = "none";
						document.getElementById("basic-modal-content").innerHTML= xmlhttp.responseText ;
					}
				  }		
				
				xmlhttp.open("POST",path+"process.php",true);
				xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				xmlhttp.setRequestHeader("Content-length", parameters.length);
				xmlhttp.setRequestHeader("Connection", "close");
				xmlhttp.send(parameters);
	
	return false;	
}

function checkAggree(theForm)
{
	var checkbox = document.getElementById('accepted');
	
	if(checkbox.checked == true)
	{
		return true;
	}
	else
	{
		alert('Please checked terms and conditions');
		return false;	
	}
	return false;	
}
function checkCartFrom(id)
{
	var field = 'quantity_'+id;
	
	var Input_value = parseInt(document.getElementById(field).value);
	var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	if(isNaN(Input_value) || Input_value <= 0)
	{
		alert("Please Enter Minimum 1 Numeric Quantity");
		document.getElementById(field).focus();
		return false;
	}
	else
	return true;
	
	return false;	
}

