function popUpFacebookShare(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=875,height=446,left = 0,top = 0');");
}

function screenshotPreview(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");								 
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

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 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 slideSwitch() {
    var $active = $('.slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('.slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('.slideshow DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
function slideSwitch2() {
    var $active = $('.slideshow1 DIV.active');

    if ( $active.length == 0 ) $active = $('.slideshow1 DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('.slideshow1 DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
$(function() {
    setInterval( "slideSwitch()", 5000 );
	setInterval( "slideSwitch2()", 5000 );
});
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 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,tubtype,amt,wt,qt) {
	//alert(id+'='+tubtype+'='+amt+'='+qt)
		$.blockUI();
		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?ID="+id+"&amount="+amt+"&wt="+wt+"&qt="+qt.value+"&tubtype="+tubtype;	
		
		
		//alert(url);
		AJAX.onreadystatechange = stateChanged;
		AJAX.open("GET",url,true);
		
		AJAX.send(null);			
		function stateChanged()
			{
				if(AJAX.readyState==4)
					{	
						setTimeout(function() { 
							$.unblockUI({ 
								onUnblock: function(){ jAlert('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.', 'ADDED SUCCESSFULLY'); } 
							}); 
						}, 2000); 					
						//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('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.', '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-550;//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 refFriend() {
	//showDiv1();
	var email = document.getElementById('txtemailref').value;
	
	if(checkEmail(email)==false) {
		jAlert('Please enter valid email address', 'INFO');	
		return false;	
	}
	$('body').addClass('fade');
    $.ajax({
         type: "POST",
         url: "refFriend.php",
         data: "hdnAction=ref&txtemail=" +email,
		 
         success: function(msg){
                    // alert( "Data Saved: " + msg );
					//alert(url);
					$('body').removeClass('fade');
					if(msg==0) {
					 jAlert('Please try again later', 'ERROR');
					}
					if(msg==2) {
					 jAlert('Already invited email address', 'ERROR');
					}
					if(msg==1) {
					 jAlert('Successfully refered to your friend', 'SUCCESS');
					}
					return false;		
                  }
			  
    });
}
function invitefreind() {
	showDiv1();	
	showDivInvite("invite");
}
function popup(windowname,id,tubtype,amt,wt,qt) {
		//alert(wt);
		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?ID="+id+"&amount="+amt+"&wt="+wt+"&qt="+qt.value+"&tubtype="+tubtype;	
		
		
		//alert(url);
		AJAX.onreadystatechange = stateChanged;
		AJAX.open("GET",url,true);
		
		AJAX.send(null);			
		function stateChanged()
			{
				if(AJAX.readyState==4)
					{	
						//setTimeout(function() { 
							//$.unblockUI({ 
								//onUnblock: function(){ jAlert('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.', 'ADDED SUCCESSFULLY'); } 
							//}); 
						//}, 2000); 					
						//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('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.', 'ADDED SUCCESSFULLY');
						var obj = document.getElementById('showcart');
						obj.style.display = 'block';
						obj.innerHTML = loadstatustext;
						showDiv();
						obj.innerHTML = AJAX.responseText;					
					}
			}	
}
