var img_height = 0;
var ishome = 1;
//Get XMLHTTP object
function $GX(handler) {
	var objXMLHttp=null
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest()
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}
//Get DOM element reference by id
function $GE(element) {
	return document.getElementById(element);
} 
function $GESD(element,st) {
	document.getElementById(element).style.display=st;
}
function set_val(hh){
//	img_height = hh;
}
function subscribe(){
	var mail = $GE('news_letter').value;
	var mob = $GE('news_mob').value;
	
	if(mob != 'Your mobile number(optional)'){
		if(mob.isNaN){
			alert("Enter valid mobile number");
			$GE('news_mob').value='';
			return;
		}else{
			if(mob.indexOf('.') != -1 || mob.indexOf('-') != -1){
				alert("Enter valid mobile number");
				$GE('news_mob').value='';
			    return;
			}else{
				if(mob.length < 10){
					alert("Enter valid mobile number");
					$GE('news_mob').value='';
			        return;
				}
			}
		}
	}else{
		mob = 'NULL'; 
	} 
	$GE('post_bt_sub').src="/img/ajax-loader.gif";
	if(mail != undefined && isEmail(mail) == true){	
		var url = '/ajax_new_site';
		var prm = 'provider=subscribe&mail='+mail+'&mob='+mob;
		XmlHttp = $GX(); 
		XmlHttp.onreadystatechange=function showResult() {
			if (XmlHttp.readyState == 4 || XmlHttp.readyState == "complete") {
				var resultofrequest = eval('(' + XmlHttp.responseText + ')')
				if(resultofrequest.success == 1) {
					$GE('post_bt_sub').src="/img/subscribe_now.gif"
					alert("Thank you for signup to our newsletter.");
					$GE('news_letter').value='';
					$GE('news_mob').value='';
					return;
				} else { 
					if(resultofrequest.success == 3) {
						$GE('post_bt_sub').src="/img/subscribe_now.gif"
						alert("You already signup for newsletter.");				
						return;
					}else{
						if(resultofrequest.success == 4){
							$GE('post_bt_sub').src="/img/subscribe_now.gif"
							alert("Enter valid mobile number");							
							$GE('news_mob').value='';
							return;
						}else{
							$GE('post_bt_sub').src="/img/subscribe_now.gif"
							alert("Sorry!! there is some problem in our system or entered email is invalid, please try after some time.");				
							return;
						}
					}
				} 
			} 
		}
		XmlHttp.open("POST",url,true);
		$Header(XmlHttp,prm);
	}else{		
		alert("Enter valid e-mail address");
		$GE('post_bt_sub').src="/img/subscribe_now.gif"
		return;
	}
} 
function loadPopup(st,srno){ 
	if(srno == 5){
		$GESD('mail_error','none'); 
		$GESD('mail_succ','none');
	}
	if(srno == 1){
		 var win_h=window.screen.height;
		 if(img_height != undefined && img_height > 0 && img_height > win_h){
//		 	$GE('fdiv1').style.height=(window.screen.height-(img_height-window.screen.height))+'px';
            if(srno == 12){            	
            	$GE('uimg_con').style.height=((window.screen.height-(img_height-window.screen.height))-50)+'px';	
            }else{
		 		$GE('large_img').style.height=((window.screen.height-(img_height-window.screen.height))-50)+'px';		 	
            }
		 }
	}
	sr_no = srno; 
	var hh=document.body.offsetHeight	
	centerPopup(srno);	
	if((srno != 4 && srno != 1 && srno != 12 && srno != 99 && srno != 2) || (srno == 12 && ishome == 1)){
         $("#fdiv"+srno).vCenter();
	}else{		
		window.scrollBy(0,-5000);
	}
	if(st == 0 && srno == 12){ 
		$GE('buy_link').innerHTML = '';
	}
	var popupStatus=st;
	if(navigator.appName=="Microsoft Internet Explorer"){
    	$GE("backgroundPopup").style.height=hh+"px";
	}		
	if(st == 1){ 
	  $("#backgroundPopup").css({  
	      "opacity": "0.6"  
	  }); 	  
	  $("#fdiv"+srno).fadeIn("slow");
      $("#backgroundPopup").fadeIn("slow");  
	}else{
	  if(srno == 103 && chk_tc != undefined){
			chk_tc = 0;
	  }
	  $("#fdiv"+srno).fadeOut("slow");  
	  $("#backgroundPopup").fadeOut("slow");		  		 
	}
}
(function($){$.fn.vCenter = function(options) {var pos = {sTop : function() {return window.pageYOffset || $.boxModel && document.documentElement.scrollTop || document.body.scrollTop;},wHeight : function() {if ( $.browser.opera || ($.browser.safari && parseInt ($.browser.version) > 520) ) { return window.innerHeight - (($(document).height() > window.innerHeight) ? 0 : 0);} else if ( $.browser.safari ) {return window.innerHeight;}else {return $.boxModel && document.documentElement.clientHeight || document.body.clientHeight;}}};return this.each(function(index) { if (index == 0) {var $this = $(this);var elHeight = $this.height();$this.css({position: 'absolute',marginTop: '0',top: pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2)});}});};})(jQuery);
function centerPopup(sr){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#fdiv"+sr).height();
	var popupWidth = $("#fdiv"+sr).width();
	var tp = windowHeight/2-popupHeight/2	
	if(tp != undefined && tp <= 0){
		tp = 0;
	}
	//centering
	$("#fdiv"+sr).css({
	"position": "absolute",
	"top": tp,
	"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
	"height": windowHeight
	}); 
}
function set_txt_val(val,iid,fl){
	var txt = $GE(iid).value;
	if(fl != undefined && fl == 1){
		$GE(iid).style.color="#BABABA";
		if(txt == val){
			$GE(iid).value="";
		}
	}else{
		if(txt.length == 0){
			$GE(iid).style.color="#BABABA";
			$GE(iid).value=val;
		}else{
			return;
		}
	}
	
}
function set_height(){	      
  var win_h = document.body.clientHeight;
  var curr_h = window.screen.height - 90;
  if(curr_h > win_h ){
      var h_to_make = curr_h - win_h;
      h_to_make = (h_to_make + win_h)-80;
      $GE('mid_con_main').style.height=h_to_make+'px';
  }      
}

function $Header(XmlHttp,prm){
	XmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	XmlHttp.setRequestHeader('A_REQUESTED_X_HEADER_UU_TZ', 'XmlHttpRequestRegister_MOZ');
	XmlHttp.send(prm);
}
   
function set_image2(img_path,twit_msg,link_url,widt,heigh,ishe,mdd5){ 	
	ishome = ishe;
	if(img_path.length > 0){
		if(widt >= 600){ 
			$GE('fdiv12').style.width = (widt+30)+'px';						
		}
		if(mdd5.length > 0){
			$GE('buy_link').innerHTML='<div style="padding:5px 0px;font-size:14px;padding-right:10px;position:absolute;margin-left:20px;"><a href="http://www.24hoursloot.com/product/'+mdd5+'" ><img src="/img/still_buy_it.gif" border="0px" alt="You can still buy it." /></a></div>';
		}
		var img_tag = '<img border="0px" width="'+widt+'px" height="'+heigh+'px" src="'+img_path+'" alt="'+twit_msg+'" title="'+twit_msg+'" />';
		var htcode = '<a target="_blank" href="'+link_url+'" >'+img_tag+'<br />';
		if(twit_msg.length > 0){ 
			htcode +='<div class="twtmsg">'+twit_msg+'</div></a>';
		}else{
			htcode +='<div class="twtmsg">View this image location on internet.</div></a>';
		}
		$GE('uimg_con').innerHTML=htcode; 
		loadPopup(1,12);
	}else{
		alert("Sorry!! selected size is not valid");		
	}  
}

function set_bigimg(iid,img,nam){
   for(var i =1;i<=6;i++){
      if(i == iid){
        $GE("img"+i).style.border="2px solid #cccccc";
      }else{
          $GE("img"+i).style.border="2px solid #ffffff";
      }	          
   }
   $GE("big_img").innerHTML="<center><div style=\'font-size:18px;color:#44260E;text-align:center;padding:5px 0px;\'>"+nam+"</div><img src=\'/img/bsale/"+img+".jpg\'  /></center>";
 }
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}


function isEmail(Mail) {
	Mail=Mail.toLowerCase();
	return (Mail.search(/^[a-zA-Z]+([_\.-]?[a-zA-Z0-9]+)*@[a-zA-Z0-9]+([\.-]?[a-zA-Z0-9]+)*(\.[a-zA-Z]{2,4})+$/) != -1);
}

