var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

var showcart =0;
function addToShopCart(action,item_id,type){
	//alert(showcart);
	if(showcart ==0){
		showcart = 1;
		$("#panel").slideUp();
		$("#panelshopcart").slideDown();
		$(this).toggleClass("active"); //return false;

	}
	url="/shop_cart/insertItem.php?item_id="+item_id+"&action="+action+"&type="+type;
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState== 4){
			if(xmlhttp.status == 200){
				radarResponse = xmlhttp.responseText;
				ajaxCart(radarResponse);
			}
		}
	}
	xmlhttp.send(null);
	return false;
}





function validateAvailability(shirt_id){
	size_id = document.getElementById('sizes_'+shirt_id)[document.getElementById('sizes_'+shirt_id).selectedIndex].value;
	url="/shirts/checkAvailability.php?s_id="+shirt_id+"&s="+size_id;
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState== 4){
			if(xmlhttp.status == 200){
				radarResponse = xmlhttp.responseText;
				if(radarResponse=='0'){
					document.getElementById('but_'+shirt_id).style.visibility='hidden';
				}else{
					document.getElementById('but_'+shirt_id).style.visibility='visible';
				}
			}
		}
	}
	xmlhttp.send(null);
	return false;
}

var xmlhttp1=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp1 = false;
}
}
@end @*/
if (!xmlhttp1 && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp1 = new XMLHttpRequest();
	} catch (e) {
		xmlhttp1=false;
	}
}
if (!xmlhttp1 && window.createRequest) {
	try {
		xmlhttp1 = window.createRequest();
	} catch (e) {
		xmlhttp1=false;
	}
}

var xmlhttp2=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp2 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp2 = false;
}
}
@end @*/
if (!xmlhttp2 && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp2 = new XMLHttpRequest();
	} catch (e) {
		xmlhttp2=false;
	}
}
if (!xmlhttp2 && window.createRequest) {
	try {
		xmlhttp2 = window.createRequest();
	} catch (e) {
		xmlhttp2=false;
	}
}

function ajaxCart(resp){

	url1="/shop_cart/ajax_cart.php";

	xmlhttp1.open("GET",url1,true);
	xmlhttp1.onreadystatechange=function(){
		if(xmlhttp1.readyState== 4) {
			if(xmlhttp1.status == 200){
				radarResponse1 = xmlhttp1.responseText;
				//alert(radarResponse1);
				document.getElementById('lyr1').innerHTML='';
				document.getElementById('lyr1').innerHTML=radarResponse1;

				initScrollLayer();
			}
		}
	}
	xmlhttp1.send(null);
	if(resp!='1'&&resp!='2'){
		if(resp=='3'){
			alert('Please login first before adding items to your shopcart');
			location.href='/members/register.php';
		}else{
			alert(resp);
		}
		
	}
	ajaxTotal();

	return false;
}

function ajaxTotal(){
	url2="/shop_cart/ajax_total.php";

	xmlhttp2.open("GET",url2,true);
	xmlhttp2.onreadystatechange=function(){
		if(xmlhttp2.readyState== 4) {
			if(xmlhttp2.status == 200){
				radarResponse1 = xmlhttp2.responseText;
				//alert(radarResponse1);
				document.getElementById('grdTotal').innerHTML='';
				document.getElementById('grdTotal').innerHTML=radarResponse1;
				initScrollLayer();
			}
		}
	}
	xmlhttp2.send(null);
	return false;
}

function checkEnter(e) {

	var key, keychar;
	key = (window.event) ? window.event.keyCode : ((e) ? e.which : null);
	if (key == null) return true;

	if(key==13){
		document.members.submit();
	}

}

function validChars(e,goods,field,max) {

	var key, keychar;
	key = (window.event) ? window.event.keyCode : ((e) ? e.which : null);
	if (key == null) return true;

	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();
	if(keychar<0) return false;
	if (goods.indexOf(keychar) != -1)
	return true;

	if (key==null || key==0 || key==8 || key==9 || key==13 || key==27)
	return true;

	return false;
}

function popImage(imageURL,imageTitle){
	//alert(imageURL);
	defaultWidth  = 600;
	defaultHeight = 600;
	//alert(imageURL);
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left=100,top=100';
	var optIE='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left=100,top=100';

	var AutoClose = false;

	if (parseInt(navigator.appVersion.charAt(0))>=4){
		var isNN=(navigator.appName=="Netscape")?1:0;
		var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
		var optNN='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left=100,top=100';
		var optIE='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left=100,top=100';

		//if (isNN){imgWin=window.open('about:blank','',optNN);}
		if (isNN){imgWin=window.open('about:blank','',optNN);}
		if (isIE){imgWin=window.open('about:blank','',optIE);}
		with (imgWin.document){
			writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
			writeln('<sc'+'ript>');
			writeln('var isNN,isIE;');
			writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
			writeln('isNN=(navigator.appName=="Netscape")?1:0;');
			writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
			writeln('function reSizeToImage(){');
			writeln('if (isIE){');
			writeln('window.resizeTo('+defaultWidth+','+defaultHeight+');');
			writeln('width='+defaultWidth+'-(document.body.clientWidth-document.images[0].width);');
			writeln('height='+defaultHeight+'-(document.body.clientHeight-document.images[0].height);');
			writeln('window.resizeTo(width,height);}');
			writeln('if (isNN){');
			writeln('window.innerWidth=document.images["Image"].width;');
			writeln('window.innerHeight=document.images["Image"].height;}}');
			writeln('function doTitle(){document.title="'+imageTitle+'";}');
			writeln('</sc'+'ript>');
			if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
			else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
			writeln('<img name="Image" src="'+imageURL+'" style="display:block"></body></html>');
			close();
		}
}

function validateEditMember(){
	var root = document.members;

	if(root.name.value==''){
		alert("Please enter your name");
		root.name.focus();
		return false;
	}
	if (root.email.value==''){
		alert('Please enter your email');
		root.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=root.email.value.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.select();
		return false;
	}
	if (root.tel.value==''){
		alert('Please enter your phone number');
		root.tel.focus();
		return false;
	}
	if (root.address.value==''){
		alert('Please enter your address address');
		root.address.focus();
		return false;
	}
	return true;
}

var resellersArray = new Array();
var cityArray = new Array();

function showReseller(){
	var regionName = document.getElementById('regionSelect').value;
	if(regionName!=''){
		document.getElementById('cityDiv').innerHTML = "&nbsp;&nbsp;&nbsp;<select name='citySelect' id='citySelect' onchange=\"listres(document.getElementById('regionSelect').value,getElementById('citySelect').value);\"><option value=''>by City</option>"+resellersArray[regionName]+"</select>";
		document.getElementById('lynxResellers').innerHTML ='';
	}
}

var load=new Image();
load.src='/images/loader.gif';

function listres(region,city){
	url2="/resellers/printReseller.php?region="+region+"&city="+city;
	xmlhttp2.open("GET",url2,true);
	xmlhttp2.onreadystatechange=function(){
		document.getElementById('loader').innerHTML="&nbsp;<img src='/images/loader.gif' width='16' height='16' align='absmiddle'>";
		if(xmlhttp2.readyState== 4) {
			if(xmlhttp2.status == 200){
				radarResponse1 = xmlhttp2.responseText;
				document.getElementById('restable').innerHTML='';
				document.getElementById('restable').innerHTML=radarResponse1;
				document.getElementById('loader').innerHTML="";
				initScrollLayer();
			}
		}
	}
	xmlhttp2.send(null);
	return false;
}

function listrest(region){
	url2="/resellers_logos/printResellerlogos.php?region="+region;
	xmlhttp2.open("GET",url2,true);
	xmlhttp2.onreadystatechange=function(){
		document.getElementById('restable1').innerHTML="&nbsp;<img src='/images/loader.gif' width='16' height='16' align='absmiddle'>";
		if(xmlhttp2.readyState== 4) {
			if(xmlhttp2.status == 200){
				radarResponse1 = xmlhttp2.responseText;
				document.getElementById('restable1').innerHTML='';
				document.getElementById('restable1').innerHTML=radarResponse1;
				initScrollLayer();
			}
		}
	}
	xmlhttp2.send(null);
	return false;
}

function linkTo(flag){
	if(flag=='1'){
		window.open('http://customer.lynx.net.lb/isppro-ui/manage.htm');
		return 1;
	}
	else{
		if(flag=='2'){
			window.open('http://mobi.lynx.net.lb/');
			return 1;
		}
		else{
			if(flag=='3'){
				window.open('http://customer.lynx.net.lb/isppro-sw-activate/manage.htm');
				return 1;
			}
			else{
				return 1;
			}
		}

	}
}