
var loadstatustext="<span style='font-size:10px;'>&nbsp;&nbsp;Loading ...</span>"
var loadstatustext2="<span style='font-size:10px;'>&nbsp;&nbsp;Loading ...</span>"
var AJAX=false;
if (window.XMLHttpRequest) // if Mozilla, Safari etc
	AJAX = new XMLHttpRequest();
else if (window.ActiveXObject){ // if IE
	try {
		AJAX = new ActiveXObject("Msxml2.XMLHTTP")
	} 
	catch (e){
		try{
			AJAX = new ActiveXObject("Microsoft.XMLHTTP")
		}
		catch (e){
			alert('ERROR! Browser does not support XMLHttpMethod')
		}
	}
}

function popLink(Link,width,Height,showScroll,isFullScreen)
{
	var strFeatures = "height="+Height+",width="+width+",status=no,titlebar=no";
	
	if(isFullScreen)
		strFeatures+=",fullscreen=yes";
	if(showScroll)
		strFeatures+=",scrollbars=yes";
		
	var popup=window.open(Link, "_blank",strFeatures);
	popup.focus();
}

function openWindow(Link)
{
	window.open(Link, "_blank");
}
function popUp_terms(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=550,height=400,left = 0,top = 0');");
}
function popUp_secure(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=450,height=300,left = 0,top = 0');");
}
function validateBlankField(obj) {
	if(trim(obj.value)=='') {
		err = document.getElementById('error');
		if(err.style.display=='none') {
			err.style.display='block';
		}
		err.innerHTML="<center>All fields marked with a (*) are mandatory. Please enter the required data.</center>";
		//alert("All * fields are mandatory");
		obj.value='';
		obj.focus();
		return false;
	}
	return true;
}

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

//validate combo box if first field is selected.
function validateCombo(cbo) {
	if(cbo.options.selectedIndex==0) { 
		var error = document.getElementById('error');
		error.innerHTML="<center>All fields marked with a (*) are mandatory.</center>";
		//alert("All * marked fields are mandatory");
		cbo.focus();
		return false;
	}
	return true;
}

function validateRadio(rad) {
	var chk=false;
		
	if(rad.length!=null) {
		for(var i=0;i<rad.length;i++) {
			if(rad[i].checked) {
				chk=true;
				break;
			}
		}
	} else {
		if(rad.checked)
			chk = true;
	}
	
	return chk;
}


function onPageChange(frm) {
	frm.submit();
}


function isDigits(argvalue) {
    argvalue = argvalue.toString();
    var validChars = "0123456789+ ";
    var startFrom = 0;
    if (argvalue.substring(0, 2) == "0x") {
       validChars = "0123456789abcdefABCDEF";
       startFrom = 2;
    } else if (argvalue.charAt(0) == "0") {
       validChars = "01234567";
       startFrom = 1;
    }
    for (var n = 0; n < argvalue.length; n++) {
        if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
    }
  return true;
}
function checkEmail(emailStr) {
       if (emailStr.length == 0) {
           return true;
       }
       var emailPat=/^(.+)@(.+)$/;
       var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
       var validChars="\[^\\s" + specialChars + "\]";
       var quotedUser="(\"[^\"]*\")";
       var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
       var atom=validChars + "+";
       var word="(" + atom + "|" + quotedUser + ")";
       var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
       var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
       var matchArray=emailStr.match(emailPat);
       if (matchArray == null) {
           return false;
       }
       var user=matchArray[1];
       var domain=matchArray[2];
       if (user.match(userPat) == null) {
           return false;
       }
       var IPArray = domain.match(ipDomainPat);
       if (IPArray != null) {
           for (var i = 1; i <= 4; i++) {
              if (IPArray[i] > 255) {
                 return false;
              }
           }
           return true;
       }
       var domainArray=domain.match(domainPat);
       if (domainArray == null) {
           return false;
       }
       var atomPat=new RegExp(atom,"g");
       var domArr=domain.match(atomPat);
       var len=domArr.length;
       if ((domArr[domArr.length-1].length < 2) ||
           (domArr[domArr.length-1].length > 5)) {
           return false;
       }
       if (len < 2) {
           return false;
       }
       return true;
}	

function sellerlogin() {

		var AJAX=false;
		if (window.XMLHttpRequest) // if Mozilla, Safari etc
			AJAX = new XMLHttpRequest();
		else if (window.ActiveXObject){ // if IE
			try {
				AJAX = new ActiveXObject("Msxml2.XMLHTTP")
			} 
			catch (e){
				try{
					AJAX = new ActiveXObject("Microsoft.XMLHTTP")
				}
				catch (e){
					alert('ERROR! Browser does not support XMLHttpMethod')
				}
			}
		}		
      var poststr = "email=" + encodeURI( document.getElementById("selleremail").value ) +
                    "&pass=" + encodeURI( document.getElementById("sellerpass").value )+
					"&timeID=" + new Date().getTime();
					
		var url = "verify_seller.php?"+poststr;	
		//alert(url);
		AJAX.onreadystatechange = stateChanged;
		AJAX.open("GET",url,true);
		
		AJAX.send(null);			
		function stateChanged()
			{
				if(AJAX.readyState==4)
					{					
					var obj = document.getElementById('success2');
					obj.style.display = 'block';
					//obj.innerHTML = loadstatustext2;
						if(AJAX.responseText!=1) {
							obj.innerHTML = AJAX.responseText;
						} else {
							document.frmglobal.submit();
						}
					}
			}
	
}

function isValidCreditCard(type, ccnum) {
   if (type == "Visa") {
      // Visa: length 16, prefix 4, dashes optional.
      var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
   } else if (type == "MasterCard") {
      // Mastercard: length 16, prefix 51-55, dashes optional.
      var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
   } else if (type == "Discover") {
      // Discover: length 16, prefix 6011, dashes optional.
      var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
   } else if (type == "American Express") {
      // American Express: length 15, prefix 34 or 37.
      var re = /^3[4,7]\d{13}$/;
   } else if (type == "Diners") {
      // Diners: length 14, prefix 30, 36, or 38.
      var re = /^3[0,6,8]\d{12}$/;
   }
   if (!re.test(ccnum)) return false;
   // Remove all dashes for the checksum checks to eliminate negative numbers
   ccnum = ccnum.split("-").join("");
   // Checksum ("Mod 10")
   // Add even digits in even length strings or odd digits in odd length strings.
   var checksum = 0;
   for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) {
      checksum += parseInt(ccnum.charAt(i-1));
   }
   // Analyze odd digits in even length strings or even digits in odd length strings.
   for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) {
      var digit = parseInt(ccnum.charAt(i-1)) * 2;
      if (digit < 10) { checksum += digit; } else { checksum += (digit-9); }
   }
   if ((checksum % 10) == 0) return true; else return false;
}	


function retrieve_user_pwd() {
		var AJAX=false;
		if (window.XMLHttpRequest) // if Mozilla, Safari etc
			AJAX = new XMLHttpRequest();
		else if (window.ActiveXObject){ // if IE
			try {
				AJAX = new ActiveXObject("Msxml2.XMLHTTP")
			} 
			catch (e){
				try{
					AJAX = new ActiveXObject("Microsoft.XMLHTTP")
				}
				catch (e){
					alert('ERROR! Browser does not support XMLHttpMethod')
				}
			}
		}		
      var poststr = "email=" + encodeURI( document.getElementById("user_email").value );
					
		var url = "check_userpwd.php?"+poststr;	
		AJAX.onreadystatechange = stateChanged;
		AJAX.open("GET",url,true);
		
		AJAX.send(null);			
		function stateChanged()
			{
				if(AJAX.readyState==4)
					{					
					var obj = document.getElementById('forgot_div');
					obj.style.display = 'block';
					obj.innerHTML = loadstatustext;
						if(AJAX.responseText!=1) {
							obj.innerHTML = AJAX.responseText;
						} else {
							document.userfrm.submit();
						}
					}
			}
	
}

function add_cart(id) {
	//alert(id+'='+tubtype+'='+amt+'='+qt)
		var AJAX=false;
		if (window.XMLHttpRequest) // if Mozilla, Safari etc
			AJAX = new XMLHttpRequest();
		else if (window.ActiveXObject){ // if IE
			try {
				AJAX = new ActiveXObject("Msxml2.XMLHTTP")
			} 
			catch (e){
				try{
					AJAX = new ActiveXObject("Microsoft.XMLHTTP")
				}
				catch (e){
					alert('ERROR! Browser does not support XMLHttpMethod')
				}
			}
		}
		var url = "add_cart.php?PID="+id;	
		
		
		//alert(url);
		AJAX.onreadystatechange = stateChanged;
		AJAX.open("GET",url,true);
		
		AJAX.send(null);			
		function stateChanged()
			{
				if(AJAX.readyState==4)
					{	
						//alert(AJAX.responseText);return false;
						//alert('This flavour has been added to your Shopping Cart as you can see on the top left-side of the screen. Click on Checkout to proceed with your order.');
						jAlert('The tyre has been added to your Shopping Cart as you can see on the top of the screen. Click on Checkout to proceed with your order.', 'ADDED SUCCESSFULLY');
						var obj = document.getElementById('showcart');
						obj.style.display = 'block';
						obj.innerHTML = loadstatustext;
						obj.innerHTML = AJAX.responseText;					
					}
			}
}

function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}

function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-250;//150 is half popup's height
	popUpDiv.style.top = popUpDiv_height + 'px';
}

function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-150;//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
}
function closepop() {
	var el = document.getElementById('blanket');
	el.style.display = 'none';
	
	var e2 = document.getElementById('popUpDiv');
	e2.style.display = 'none';
	
}
function addcart_new(id,qt) {
		showDiv1();
		var AJAX=false;
		if (window.XMLHttpRequest) // if Mozilla, Safari etc
			AJAX = new XMLHttpRequest();
		else if (window.ActiveXObject){ // if IE
			try {
				AJAX = new ActiveXObject("Msxml2.XMLHTTP")
			} 
			catch (e){
				try{
					AJAX = new ActiveXObject("Microsoft.XMLHTTP")
				}
				catch (e){
					alert('ERROR! Browser does not support XMLHttpMethod')
				}
			}
		}
		var url = "add_cart.php?PID="+id+"&QT="+qt;	
		
		
		//alert(url);
		AJAX.onreadystatechange = stateChanged;
		AJAX.open("GET",url,true);
		
		AJAX.send(null);			
		function stateChanged()
			{
				if(AJAX.readyState==4)
					{	
						//alert(AJAX.responseText);return false;
						//alert('This flavour has been added to your Shopping Cart as you can see on the top left-side of the screen. Click on Checkout to proceed with your order.');
						//jAlert('The tyre has been added to your Shopping Cart as you can see on the top of the screen. Click on Checkout to proceed with your order.', 'ADDED SUCCESSFULLY');
						var obj = document.getElementById('showcart');
						obj.style.display = 'block';
						obj.innerHTML = loadstatustext;
						showDiv();
						obj.innerHTML = AJAX.responseText;					
					}
			}	
		

}
function _addcart_new(id,qt) {
		showDiv1();
		var AJAX=false;
		if (window.XMLHttpRequest) // if Mozilla, Safari etc
			AJAX = new XMLHttpRequest();
		else if (window.ActiveXObject){ // if IE
			try {
				AJAX = new ActiveXObject("Msxml2.XMLHTTP")
			} 
			catch (e){
				try{
					AJAX = new ActiveXObject("Microsoft.XMLHTTP")
				}
				catch (e){
					alert('ERROR! Browser does not support XMLHttpMethod')
				}
			}
		}
		var url = "add_cart.php?PID="+id+"&QT="+qt.value;	
		
		
		//alert(url);
		AJAX.onreadystatechange = stateChanged;
		AJAX.open("GET",url,true);
		
		AJAX.send(null);			
		function stateChanged()
			{
				if(AJAX.readyState==4)
					{	
						//alert(AJAX.responseText);return false;
						//alert('This flavour has been added to your Shopping Cart as you can see on the top left-side of the screen. Click on Checkout to proceed with your order.');
						//jAlert('The tyre has been added to your Shopping Cart as you can see on the top of the screen. Click on Checkout to proceed with your order.', 'ADDED SUCCESSFULLY');
						var obj = document.getElementById('showcart');
						obj.style.display = 'block';
						obj.innerHTML = loadstatustext;
						showDiv();
						obj.innerHTML = AJAX.responseText;					
					}
			}	
		

}
function addcartaccess_new(id,qt) {
		showDiv1();
		var AJAX=false;
		if (window.XMLHttpRequest) // if Mozilla, Safari etc
			AJAX = new XMLHttpRequest();
		else if (window.ActiveXObject){ // if IE
			try {
				AJAX = new ActiveXObject("Msxml2.XMLHTTP")
			} 
			catch (e){
				try{
					AJAX = new ActiveXObject("Microsoft.XMLHTTP")
				}
				catch (e){
					alert('ERROR! Browser does not support XMLHttpMethod')
				}
			}
		}
		var url = "add_cart_access.php?PID="+id+"&QT="+qt.value;	
		
		
		//alert(url);
		AJAX.onreadystatechange = stateChanged;
		AJAX.open("GET",url,true);
		
		AJAX.send(null);			
		function stateChanged()
			{
				if(AJAX.readyState==4)
					{	
						//alert(AJAX.responseText);return false;
						//alert('This flavour has been added to your Shopping Cart as you can see on the top left-side of the screen. Click on Checkout to proceed with your order.');
						//jAlert('The tyre has been added to your Shopping Cart as you can see on the top of the screen. Click on Checkout to proceed with your order.', 'ADDED SUCCESSFULLY');
						var obj = document.getElementById('showcart');
						obj.style.display = 'block';
						obj.innerHTML = loadstatustext;
						showDiv();
						obj.innerHTML = AJAX.responseText;					
					}
			}	
		

}
function addcartaccess_new2(id,qt) {
		//showDiv1();
		var AJAX=false;
		if (window.XMLHttpRequest) // if Mozilla, Safari etc
			AJAX = new XMLHttpRequest();
		else if (window.ActiveXObject){ // if IE
			try {
				AJAX = new ActiveXObject("Msxml2.XMLHTTP")
			} 
			catch (e){
				try{
					AJAX = new ActiveXObject("Microsoft.XMLHTTP")
				}
				catch (e){
					alert('ERROR! Browser does not support XMLHttpMethod')
				}
			}
		}
		var url = "add_cart_access2.php?PID="+id+"&QT="+qt.value;	
		
		
		//alert(url);
		AJAX.onreadystatechange = stateChanged;
		AJAX.open("GET",url,true);
		
		AJAX.send(null);			
		function stateChanged()
			{
				if(AJAX.readyState==4)
					{	
						//alert(AJAX.responseText);return false;
						//alert('This flavour has been added to your Shopping Cart as you can see on the top left-side of the screen. Click on Checkout to proceed with your order.');
						//jAlert('The tyre has been added to your Shopping Cart as you can see on the top of the screen. Click on Checkout to proceed with your order.', 'ADDED SUCCESSFULLY');
						var obj = document.getElementById('cartsho');
						obj.style.display = 'block';
						//$("div.cartsho").toggle("slow");
						obj.innerHTML = "<img src='js/jquery/loading.gif'>";
						//showDiv();
						obj.innerHTML = AJAX.responseText;					
					}
			}	
		

}
