var httpObj = false;
		try {
			  httpObj = new XMLHttpRequest();
		} catch (trymicrosoft) {
		  try {
				httpObj = new ActiveXObject("Msxml2.XMLHTTP");
		  } catch (othermicrosoft) {
			try {
			  httpObj = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
			  httpObj = false;
			}
	  }
	}
function popupAjaxRequest(){
	var httpObj = false;
		try {
			  httpObj = new XMLHttpRequest();
		} catch (trymicrosoft) {
		  try {
				httpObj = new ActiveXObject("Msxml2.XMLHTTP");
		  } catch (othermicrosoft) {
			try {
			  httpObj = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
			  httpObj = false;
			}
	  }
	}
}
jQuery(document).ready(function() {
			  	
				jQuery("#nav").nav();
				
		//jQuery("#content-1 .carousel").carousel();
	
				
			  });
function captureHitEnter(e, func_with_param) {
	var characterCode;

	if(e && e.which){
		e = e
		characterCode = e.which
	}
	else{
		e = event;
		characterCode = e.keyCode
	}
	if(characterCode == 13){
		eval(func_with_param);
		return false;
	}
	else{
			return true;
	}
}

function CheckPinCode(str){
	if(str=='') return "Please enter Pincode";
	else if( !IsOnlyNumbers(str) ) return "Only numbers are allowed in Pincode";
	else if( str.length != 6 ) return "Pincode must be 6 characters long";
	else if( str.charAt(0) == '0' ) return "First digit of your pincode number must be other 0";
	else return false;
}

function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}

function checkMobileNumber(mobile_no) {
	if( !IsOnlyNumbers(mobile_no) ) return "Only numbers are allowed in Mobile number!";
	else if( mobile_no.length != 10 ) return "Mobile number must be 10 characters long!";
	else if( mobile_no.charAt(0) != '9' && mobile_no.charAt(0) != '8' && mobile_no.charAt(0) != '7' ) return "First digit of your mobile number must be 9 or 8 or 7";
	//else if(mobile_no.substring(0, 2)=='91') return "First digit of your mobile number must be 9";
	else return false;
}

function IsOnlyNumbers(str) {
	var nonums = /^[0-9]*$/;
	if (nonums.test(str))
	return true;
	else
	return false;
}

function IsOnlyZeros(str) {
	var nonums = /^[0]*$/;
	if (nonums.test(str))
	return true;
	else
	return false;
}

function CountingMobileZeros(mobile_no){
	var count = 0;

	for(i=mobile_no.length;i>(mobile_no.length-5);i--){
		var chr = mobile_no.charAt(i);
		if(chr=='0'){
			count++;
		}
	}
	if(count<4)
		return true;
	else
		return false;
}

function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit)
	field.value = field.value.substring(0, maxlimit);
	else
	cntfield.value = maxlimit - field.value.length;
}


function IsOnlyChars(name) {
    str = "0123456789";
	//alert(name);
    for(i=0; i<name.length; i++) {
        if(str.indexOf(name.charAt(i)) != -1) {
            return true;
        }
    }
    return false;
}

function IsAlphaNumeric(name){
	var str="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
	var flag = 0;
    for(i=0; i<name.length; i++) {
        if(str.indexOf(name.charAt(i)) != -1) {
            flag = 0;
        }else{
			flag = 1;			
			return true;
		}
    }
	return false;
}

function containSpecialCharacters(str, exclude) {
    
    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
    if(exclude) {
        for (var j=0; j < exclude.length; j++) {
            iChars = iChars.replace(exclude.charAt(j), '');
        }
    }
	//alert(iChars);
    for (var i = 0; i < str.length; i++) {
        if (iChars.indexOf(str.charAt(i)) != -1) {
            return true;
        }
    }
    return false;
}


function checkFirstLastCharacter(str) {

    var iChars = "_.";

    //for First character
    if (iChars.indexOf(str.charAt(0)) != -1) {
        return true;
    }
    //for Last character
    if (iChars.indexOf(str.charAt(str.length-1)) != -1) {
        return true;
    }
}



function checkNameValidity(name) {
	if(name=='') return "Please enter ";
    else if( containSpecialCharacters( name, ' ')) return "Special characters are not allowed in ";
    else if( checkFirstLastCharacter(name) ) return "Special characters are not allowed at Start or End of ";
    else if(IsOnlyChars(name)) return "Only alphabets are allowed in ";
    else return false;
}
function checkUserNameValidity(name) {
	if(name=='') return "Please enter ";
    else if( containSpecialCharacters( name, '.')) return "Special characters are not allowed in ";
    else if( checkFirstLastCharacter(name) ) return "Special characters are not allowed at Start or End of ";
    else if(IsOnlyChars(name)) return "Only alphabets are allowed in ";
    else return false;
}

// Validation for Registration Module

function CapitalizeMe(val) {
	
	var CapitalString = val.toUpperCase();
	var firstchar = CapitalString.substring(0,1);
	var reststring = CapitalString.substring(1);
	var SmallString = reststring.toLowerCase();

	var name = firstchar+SmallString;
	return name;
}



function inValidPassword(text) {
    if(text.length < 6) return 'Password has to be 6-18 characters.';
    else if(text.length >18) return 'Password has to be 6-18 characters.';
   
}

function NameValidity(str){
	var NameFilter = /^[A-Za-z ]{1,}$/;
	//var NameFilter = /^[A-Za-z]{1,}$/;
	
	if(!NameFilter.test(str)) return "Incorrect Name.";
	else return false;
}

function EmailValidity(str){
	var EmailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	if(!EmailFilter.test(str)) return "Enter valid e-mail address.";
	else return false;
}

function MobileValidity(mobile_no) {
	if( !IsOnlyNumbers(mobile_no) ) return "Mobile number seems to be incorrect.";
	else if( mobile_no.length != 10 ) return "Mobile number must be 10 characters long.";
	else if( mobile_no.charAt(0) != '9'  && mobile_no.charAt(0) != '8' && mobile_no.charAt(0) != '7') return "Mobile number seems to be incorrect.";
	else return false;
}







function delayer(CampUrl){
	
    window.location =CampUrl;
}

var Authentication ='NO';
function Showmask2(Camp,Client,CampUrl){
	
	var url = urlpath+"popup-camp.php?Camp="+Camp+"&Client="+Client;
	httpObj.open("POST",url,true);
	httpObj.onreadystatechange = function(){		
		if(httpObj.readyState==1||httpObj.readyState==2||httpObj.readyState==3){
			document.getElementById('fade_bg55').style.width="500px";
			document.getElementById('fade_bg55').innerHTML = '<div class="close_btn" onClick="CloseLoginDiv();" ></div><div class="popup"><div class="pop_header" style="height:240px;"><div style="position:absolute;padding:100px 0px 100px 200px;"><img src="'+urlpath+'images/loading.gif"/></div><div class="clear"></div><div class="redirecting_div"></div></div><div class="clear"></div></div>';
			document.getElementById('fade_bg_main').style.display = 'block';
		}
		if(httpObj.readyState==4){
			Authentication ='OK';
			strContent=httpObj.responseText;
			document.getElementById('fade_bg55').innerHTML = strContent;
			document.getElementById('fade_bg55').style.width="500px";
			document.getElementById('fade_bg_main').style.display = 'block';
			if(Authentication=='OK'){
				setTimeout(delayer(CampUrl), 4000);
			}
		}
	}
	httpObj.send(null);
}


function ShowSingleSignonSignup(SingleSignOnEmail){	
	
	var url = urlpath+"singlesignon-signup.php?SingleSignOnEmail="+SingleSignOnEmail;
	
	httpObj.open("POST",url,true);
	httpObj.onreadystatechange = function(){		
		if(httpObj.readyState==1||httpObj.readyState==2||httpObj.readyState==3){			
			document.getElementById('popupform').style.height='500px';
			document.getElementById('popupform').innerHTML = '<div style="position:absolute;padding:250px 0px 200px 400px;"><img src="'+urlpath+'images/loading.gif"/></div>';
			document.getElementById('fade_bg_main').style.display = 'block';
		}
		if(httpObj.readyState==4){
			strContent=httpObj.responseText;
			document.getElementById('fade_bg55').innerHTML = strContent;
			document.getElementById('fade_bg_main').style.display = 'block';
		}
	}
	httpObj.send(null);
}

function hShowmask(){
		document.getElementById('hsignup').style.display = 'block';
}

function CloseLoginDiv(){
	
	document.getElementById('fade_bg_main').style.display = 'none';
	document.getElementById('div_fade_bg_mask').style.display='none';
		
}

function addBookmark(title,url) {
	if (window.sidebar) { 
	window.sidebar.addPanel(title, url,""); 
	} else if( document.all ) {
	window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		
	return true;
	}
}
function setLocationHref(RedUrl){
	//window.location.href(RedUrl);
	window.location.href=RedUrl;
}
var childWin;
function openFbWin(){
  childWin = fb_window();
  if (window.focus) 
    childWin.focus();
}
function callLink(){
	var ifra =document.createElement('iframe');
	ifra.name = ifra.id = "iframeLin";
	ifra.style.height = ifra.style.width = '0px';
	ifra.style.border = 'none';	
	ifra.src = urlpath+"facebookconnect.php";
	document.body.appendChild(ifra);	
}

function fb_window(){
	t=(screen.height/2)-(420/2);
	l=(screen.width/2)-(470/2);
	callLink();	
	return window.open('https://www.facebook.com/login.php?api_key='+apikey+'&display=popup&req_perms=publish_stream,email,user_birthday&return_session=1&next='+urlpath+'facebookconnect.php','FBConnectWindow','status=0,toolbar=0,resizable=1,scrollbars=1,menubar=0,width=488,height=420,top='+t+',left='+l);	
}
var childWin1;
function openFbWin1(){
  childWin1 = fb_window1();
  if (window.focus) 
    childWin1.focus();
}
function callLink1(){
	var ifra =document.createElement('iframe');
	ifra.name = ifra.id = "iframeLin";
	ifra.style.height = ifra.style.width = '0px';
	ifra.style.border = 'none';	
	ifra.src = urlpath+"quickfacebookconnect.php";
	document.body.appendChild(ifra);	
}

function fb_window1(){
	t=(screen.height/2)-(420/2);
	l=(screen.width/2)-(470/2);
	//callLink1();	
	return window.open('http://www.facebook.com/login.php?api_key='+apikey+'&display=popup&req_perms=publish_stream,email,user_birthday&return_session=1&next='+urlpath+'quickfacebookconnect.php','FBConnectWindow','status=0,toolbar=0,resizable=1,scrollbars=1,menubar=0,width=488,height=420,top='+t+',left='+l);	
}

function ShowReferPopup(){	

	document.getElementById('fade_bg55').style.width='700px';
	document.getElementById('fade_bg55').style.top='60px';
	document.getElementById('div_fade_bg_mask').style.display='block';
	var url = urlpath+"ShowReferPopup.php";
	popupAjaxRequest();
	httpObj.open("POST",url,true);
	httpObj.onreadystatechange = function(){		
		if(httpObj.readyState==1||httpObj.readyState==2||httpObj.readyState==3){			
			//document.getElementById('MerchantPopup').style.height='500px';
			document.getElementById('MerchantPopup').innerHTML = '<div style="position:absolute;padding:250px 0px 200px 400px;"><img src="'+urlpath+'images/loading.gif"/></div>';
			document.getElementById('fade_bg_main').style.display = 'block';
		}
		if(httpObj.readyState==4){
			strContent=httpObj.responseText;
			document.getElementById('fade_bg55').style.width='700px';
			document.getElementById('fade_bg55').innerHTML = strContent;
			document.getElementById('fade_bg_main').style.display = 'block';
		}
	}
	httpObj.send(null);
}

