// global variable

var moduleId = "";

	function dgebid(obj){
		if(document.getElementById){
			if(document.getElementById(obj)!=null){return document.getElementById(obj)}else{return "";}
		}else if(document.all){
			if(document.all[obj]!=null){return document.all[obj]}else{return "";}
		}
	}

	function toggle(show,hide){
		if(!hide){
			if (dgebid(show).style.display != "none") {dgebid(show).style.display = 'none';} else {dgebid(show).style.display = "";}
		}else{		
			dgebid(hide).style.display="none";
			dgebid(show).style.display="block";
		}
	}

	function tab(id,ttab,cname,csson,cssoff) {		
		for (i=1; i<=ttab; i++){
			container = cname + i;			
			if(id == "l"+i && container!=undefined){dgebid(container).style.display = "block"; dgebid("l"+i).className= csson;}
			else if(container!=undefined){dgebid(container).style.display = "none"; dgebid("l"+i).className= cssoff;}
		}
	}


	function genNumbers() {
	  var d=new Date();
	  var rand_flag = "sr"+d.getSeconds()+"we";
	  return rand_flag;
	}	

	function findloc()
	{
		var loc=location.href;
		loc=loc.toLowerCase();
		loc=loc.substring(0,(loc.indexOf('.com/')))
		dm=loc.substring(loc.indexOf('.'),loc.length)
		dm=dm+".com"
		return dm
	}

	function setCookie(c_name,value)
	{document.cookie = c_name + "=" + escape(value)+";DOMAIN="+findloc()+";PATH=/";}

	/*Get cookie value*/
	function GetCookie(name)
	{
	var cname = name + "=";
	var dc = document.cookie;
		if (dc.length > 0)
		{ 
			begin = parseInt(dc.indexOf(cname));
			if (begin >= 0)
			{
				begin += cname.length;
				end = dc.indexOf(";", begin);
				if (end == -1) end = dc.length;
				return unescape(dc.substring(begin, end));
			}
		}
	return null;
	}

	function CallAlert()
	{
		setCookie('swf_ck','null');
	}

	//Ajax Function
	var reqSent = 0;
	function jqajaxRequest(file,method,qs,storeContent){ 
		
		if(arguments[4] =='' || arguments[4] == undefined) dt = 'HTML';
		else dt = arguments[4];

		if(arguments[5] =='' || arguments[5] == undefined) callbackfunction = '';
		else callbackfunction = arguments[5];
 		qs = qs+"&closediv="+storeContent;

		if(reqSent==1){return false;}else{
		$.ajax({  
			url: file,	
			type: method,
			data: qs,
			cache:false,
			dataType: dt,
			//async: false,
			timeout: 30000,
			beforeSend: function(){ 
				reqSent =1;
				$("#"+storeContent).html('<center><img src="http://imgs.bharatmatrimony.com/bmimgs/small_loading.gif"></center>');
				$("#"+storeContent).show();//$.colorbox.resize();
			},
			success: function (html) {
				$("#"+storeContent).fadeOut(0).fadeIn("slow");
				$("#"+storeContent).html(html);
				if(callbackfunction != ''){
					callbackfunction(); 
				}$(".litebox").colorbox($.extend({}, getParameters())); $.colorbox.resize();
			},
			complete: function (jqXHR,textStatus) {
				reqSent =0;
				if(textStatus == 'timeout'){
					$("#"+storeContent).html('<div class="padd5 lheight16"><font color="#ff0000">Request timed out.</font> <a href="javascript:void(0)" onclick=jqajaxRequest(\''+file+'\',\''+method+'\',\''+qs+'\',\''+storeContent+'\',\''+dt+'\') class="clr1">Click here</a> <font color="#000000">to try again.</font><br />If you continue to face the problem there could be an issue with your<br />Internet connection.</div>');
					var jerror = file + "?"+ qs + " : "+ textStatus;
					WriteToErrorFile(jerror); 
				}
			},
			error: function (jqXHR,textStatus,errorThrown) { 
				if(jqXHR.status == 500 || jqXHR.status == 404){
					var jerror = file + "?"+ qs + " : " + errorThrown;
					WriteToErrorFile(jerror);
				}
			}
		}); }
	}


	function WriteToErrorFile(errorURL){
		var replaceerrorUrl=errorURL.replace('http://','');
		var qstrring=replaceerrorUrl.replace(/&/g,'~');
		$.ajax({
			url	: "/iptracking.php",
			type	: 'GET',
			data	: 'fname='+qstrring+'~trand='+genNumbers(),
			success: function (html) {  }		
		});	
	}


	function getParameters(){
		var
		settingsObject = {},
		hash,
		hashes = location.search.substring(1).split(/&/);
		for(var i = 0; i < hashes.length; i++){
			hash = hashes[i].split('=');
			settingsObject[hash[0]] = hash[1];
		}
		return settingsObject;
	}




	// Common functions used in bm

function IsEmpty(obj, obj_type)
{
	if (obj_type == "text" || obj_type == "password" || obj_type == "textarea" || obj_type == "file")	{
		var objValue;		
		objValue = $(obj).attr("value").replace(/\s+$/,"");
		if (objValue.length == 0) {
			return true;
		} else {
			return false;
		}
	} else if (obj_type == "select" || obj_type == "select-one") {
		for (i=0; i < obj.length; i++) {
			if (obj.options[i].selected) 
				{
					if(obj.options[i].value==" ") 
					{return true;obj.focus();} else {return false;}
					
					if(obj.options[i].value == "0") 
					{
						if(obj.options[i].seletedIndex == "0") 
						{return true;obj.focus();}
					} else {return false;}
				}
			
		}
		return true;	
	} else if (obj_type == "radio" || obj_type == "checkbox") {
		if (!obj[0] && obj) {
			if (obj.checked) {
				return false;
			} else {
				return true;	
			}
		} else {
			for (i=0; i < obj.length; i++) {
				if (obj[i].checked) {
					return false;
				}
			}
			return true;
		}
	} else {
		return false;
	}
}

function CompareValue( NumStr, pattern )
{
	for( var Idx = 0; Idx < NumStr.length; Idx ++ )
	{
		 var Char = NumStr.charAt( Idx );
		 var Match = false;

		for( var Idx1 = 0; Idx1 < pattern.length; Idx1 ++)
		{
		 if( Char == pattern.charAt( Idx1 ) )
		 Match = true;
		}
		if ( !Match )
		return false;
 	}
   	return true;
}


function ValidateEmail(Email)
{
	var funRegExp	      = new RegExp("^[A-Za-z0-9][A-Za-z0-9_\\.\-]*\\@[a-zA-Z0-9\-]+\\.[a-zA-Z]+[\\.]?[a-zA-Z]*$");
	if (!Email.match(funRegExp)) { return false; }//if
	return true;
}

function enterfiled(rowid)
{document.getElementById(rowid).className="rowcolor";}

function onexit(rowid)
{document.getElementById(rowid).className="normalrow";}

function ChkEmpty(obj,obj_type,rowid,spanname,msg)
{	
	if (obj_type=="text" || obj_type=="password" || obj_type=="textarea" || obj_type=="file")
	{
		var objValue;
		objValue = obj.value.replace(/\s+$/,"");
		if (objValue.length == 0)
		{document.getElementById(rowid).className="normalrow";document.getElementById(spanname).innerHTML=msg;return true;} 
		else {document.getElementById(rowid).className="normalrow";document.getElementById(spanname).innerHTML=" ";return false;}
	} 
	
	if (obj_type == "select") 
	{
		if (obj.selectedIndex==0)
		{document.getElementById(rowid).className="normalrow";document.getElementById(spanname).innerHTML=msg;return true;} 
		else {document.getElementById(rowid).className="normalrow";document.getElementById(spanname).innerHTML="";return false;}
		return true;	
	} 
	
	if (obj_type == "radio" || obj_type == "checkbox") 
	{
		var objlength=obj.length
		var objcount=0;
		for (i=0;i<objlength;i++ )
		{
			if(obj[i].checked){objcount=1;break;}else{objcount=0;}
		}
		if(objcount==0)
		{document.getElementById(rowid).className="normalrow";document.getElementById(spanname).innerHTML=msg;}
		else{document.getElementById(rowid).className="normalrow";document.getElementById(spanname).innerHTML=" ";}
		
		return true;
	} 
	
		return false;
}


function ValidateNo( NumStr, String )
{
	for( var Idx = 0; Idx < NumStr.length; Idx ++ )
	{
		 var Char = NumStr.charAt( Idx );
		 var Match = false;

		for( var Idx1 = 0; Idx1 < String.length; Idx1 ++)
		{
		 if( Char == String.charAt( Idx1 ) )
		 Match = true;
		}

		if ( !Match )
		return false;
 	}
   	return true;
}

function replaceAlpha(strIn) {
	var strOut='';
	for(var i=0 ; i < strIn.length ; i++) {
		var cChar=strIn.charAt(i);
		if((cChar >= 'A' && cChar <= 'Z') || (cChar >= 'a' && cChar <= 'z') || (cChar >= '0' && cChar <= '9')) {
			strOut += cChar;
		} else {
			strOut += "_";
		}
	} return strOut;
}

var t_msgn;

function launchIC(userID,destinationUserID) // click to open for chat online link
{

	if(NODECHAT!=undefined && NODECHAT=="1"){

		var memberIdArr = destinationUserID.split("_");
		jqcc.cometchat.chatWith(memberIdArr[0]);

	}else{

		cmsgreq='';	 // test should remove
		var dest_id=destinationUserID.split('_');

		if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
		{ 
			var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
			if (ffversion>=3)
			{winwidth="500";winheight="310";}
			else 
			{winwidth="500";winheight="310";}
		}
		else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
		{winwidth="500";winheight="310";}
		else
		{winwidth="500";winheight="310";}
		var wintitle=userID+"vs"+dest_id[0];

		if(cmsgreq==1)
		{var winurl="http://chat."+DOMAINARRAY['domainnameshort']+"matrimony.com/chat/chatwindow.php?myid="+userID+"&recpid="+dest_id[0];}
		else
		{var winurl="http://"+DOMAINARRAY['domainmodule']+"/chat/chatwindow.php?myid="+userID+"&recpid="+dest_id[0];}

		window.open(winurl,wintitle,"width="+winwidth+",height="+winheight+",toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=0");

	}
}

function launch_auto(userID,destinationUserID,firstmsg) //auto open and click to open via webnotification
{
	var dest_id=destinationUserID.split('_');	
	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
	{ 
		var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		if (ffversion>=3)
		{winwidth="500";winheight="310";}
		else 
		{winwidth="500";winheight="310";}
	}
	else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
	{winwidth="500";winheight="310";}
	else
	{winwidth="500";winheight="310";}
	var wintitle=userID+"vs"+dest_id[0];
		
	if(cmsgreq==1)
	{var winurl="http://chat."+DOMAINARRAY['domainnameshort']+"matrimony.com/chat/chatwindow.php?myid="+userID+"&recpid="+dest_id[0]+"&firstmsg="+firstmsg;}
	else
	{var winurl="http://"+DOMAINARRAY['domainmodule']+"/chat/chatwindow.php?myid="+userID+"&recpid="+dest_id[0]+"&firstmsg="+firstmsg;}


	var is_chat_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;

	if(is_chat_chrome==true)
	{
			var newwin=window.open("","test","width=0,height=0");
			checkPopupBlocked(newwin,userID,destinationUserID,firstmsg);
	}
	else
	{
		var popupWindowTest=null;
		popupWindowTest=window.open(winurl,wintitle,"width="+winwidth+",height="+winheight+",toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=0");

		if(popupWindowTest==null) 
		{			
			if(cmsgreq==1)
			{setCookie("mpb",userID+"@"+destinationUserID+"@"+firstmsg.substring(0,50));}
			else
			{
				var cl_win_id="";
				if(GetCookie("closewin")==null || GetCookie("closewin")=="null"){setCookie("closewin",dest_id[0]);}
				else{cl_win_id=GetCookie("closewin")+"~"+dest_id[0];setCookie("closewin",cl_win_id);}
				alert("Your popup blocker stopped an InstantCommunicator window from opening. Please disable it.");
			}
		}
	}
}

function checkPopupBlocked(poppedWindow,userID,destinationUserID,firstmsg) 
{
 setTimeout(function(){doCheckPopupBlocked(poppedWindow,userID,destinationUserID,firstmsg);}, 5000);
}

function doCheckPopupBlocked(poppedWindow,userID,destinationUserID,firstmsg) 
{
    var result = false;
    if (poppedWindow && poppedWindow.outerWidth == 0) {result = true;}

	if(result)
    {//The popup was blocked.
		poppedWindow.close();		
		if(cmsgreq==1)
		{setCookie("mpb",userID+"@"+destinationUserID+"@"+firstmsg.substring(0,50));}
		else{alert("Your popup blocker stopped an InstantCommunicator window from opening. Please disable it.");}
	}
	else
	{//The popup was not blocked.
		poppedWindow.close();
		var dest_id=destinationUserID.split('_');
		var wintitle=userID+"vs"+dest_id[0];
		
		if(cmsgreq==1)
		{var winurl="http://chat."+DOMAINARRAY['domainnameshort']+"matrimony.com/chat/chatwindow.php?myid="+userID+"&recpid="+dest_id[0]+"&firstmsg="+firstmsg;}
		else
		{var winurl="http://"+DOMAINARRAY['domainmodule']+"/chat/chatwindow.php?myid="+userID+"&recpid="+dest_id[0]+"&firstmsg="+firstmsg;}

		var cwin=window.open(winurl,wintitle,"width=500,height=310,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=0");
	}
}

var VideoCheckRequest= funVideoMakeObject();
function funProtectedPassword()
{
	var frmName	=	document.frmProtectedPassword;
	if ((frmName.password.value).replace(' /\s+/','') == ''){
		document.getElementById('protecterror').innerHTML='Enter Password';
		frmName.password.value = '';
		frmName.password.focus();
		return false;
	} else {
		document.getElementById('protecterror').innerHTML='&nbsp';
	}
	var arguments	= 'password='+frmName.password.value+'&frmPasswordSubmit='+frmName.frmProtectedPasswordSubmit.value+'&matriId='+frmName.matriId.value;
	var URL			=	'http://'+DOMAINARRAY["domainmodule"]+'/video/video-view.php';
	VideoCheckRequest = MakePostRequest(URL,arguments,'VideoAjaxCallBack');
	return true;
}//funProtectedPassword



function funDisplayPassword(){
	var frmname	=	this.document.frmPassworddisplay;
	var arguments	= 'matriId='+frmname.matriId.value;
	var URL			= 'http://'+DOMAINARRAY["domainmodule"]+'/video/video-view-password.php';
	VideoCheckRequest = MakePostRequest(URL,arguments,'VideoAjaxCallBack');
	return true;
}//funDisplayPassword

function funVideoSpeed(speed,oppositematriId,URL,width,height,password,name) {
	window.open( "http://"+DOMAINARRAY['domainmodule']+"/video/show-video.php?videospeed="+speed+"&matriId="+oppositematriId+"&password="+password+"&name="+name+"", "myWindow","status = 1, height ="+height+", width = "+width+", resizable = 0")
}

function VideoAjaxCallBack()
{
	if (VideoCheckRequest.readyState == 4) 
	{
		if (VideoCheckRequest.status == 200)
		 {
			 document.getElementById('video').innerHTML	 = VideoCheckRequest.responseText;

		 }
		 else alert('There was a problem with the request.'); 
	}
}//VideoAjaxCallBack

function funVideoMakeObject(){
	var response;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")	{
		response = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		response = new XMLHttpRequest();
	}
	return response;
}

//savesearch
function savesearchsubmit(formid) {
	var js_randid=genNumbers();
	var frm=eval("document.frm_"+formid); 
	frm.randid.value=js_randid;
	document.forms[0].submit();
}

function formFocus(frmName) {eval('document.'+frmName+'.elements[0].focus();');}
window.status = "BharatMatrimony.com";


/* Toll Number {*/
var ban_country=GetCookie("USERCNTRY");
function hp_phone() {
	if(ban_country!=null) {
		/* banner for india */ if(ban_country == 98) { document.getElementById('phnodiv').innerHTML='1-800-425-3344 (BSNL/MTNL) | 1-800-3000-3344 (Others)'; document.getElementById('bancountryname').innerHTML=" INDIA"; if (document.getElementById('privtollnum')) { document.getElementById('privtollnum').innerHTML="1800-3000-3456"; } }
		/* banner for uae */ else if(ban_country == 220) { document.getElementById('phnodiv').innerHTML="971-4-3968637"; document.getElementById('bancountryname').innerHTML=" UAE"; if (document.getElementById('privtollnum')) { document.getElementById('privtollnum').innerHTML="+97150-140-2940"; } }
		/* banner for usa */ else if(ban_country == 222) { document.getElementById('phnodiv').innerHTML="1-888-824-6146"; document.getElementById('bancountryname').innerHTML=" USA"; if (document.getElementById('privtollnum')) { document.getElementById('privtollnum').innerHTML="8668076684"; } }
		/* banner for uk */ else if(ban_country == 221) { document.getElementById('phnodiv').innerHTML="0-808-168-3055"; document.getElementById('bancountryname').innerHTML=" UK"; if (document.getElementById('privtollnum')) { document.getElementById('privtollnum').innerHTML="8081683096"; } }
		/* banner for other countries */ else { document.getElementById('phnodiv').innerHTML="1-800-3000-3344 (India)"; document.getElementById('bancountryname').innerHTML=""; if (document.getElementById('privtollnum')) { document.getElementById('privtollnum').innerHTML="1-888-824-6146"; } }
	}
}
/* Toll Number }*/

/* Closing function for Express Interest and send mail and voice*/
function closeexpmsg(divid) { 
	$('#'+divid).html(''); 
	$('#'+divid).hide(); 
	if(moduleId == "VP") {
		$('#phouterborder').css("border-bottom","none");
		$('#msgvoice').hide();
	}	
}

// Function used for Apply class while clicking a link from  show all left panel
 function ChangeHighlights(id) {
	  $('#eireceive').removeClass("linkon");
	  $('#eisent').removeClass("linkon");
	  $('#rqreceive').removeClass("linkon");
	  $('#rqsent').removeClass("linkon");
	  $('#inbreceive').removeClass("linkon");
	  $('#inbsent').removeClass("linkon");
	  $('#vmreceive').removeClass("linkon");
	  $('#vmsent').removeClass("linkon");
         $('#lvsl').removeClass("linkon");
	  $('#lvvpn').removeClass("linkon");
	  $('#lvig').removeClass("linkon");
	  $('#lvbk').removeClass("linkon");
	  $('#lvvmp').removeClass("linkon");
	  $('#lvvmpn').removeClass("linkon");
	  $('#'+id).addClass("linkon");
 }

 function validateById(){
	var MatriFormSBID = this.document.MatriFormSBID;
	if(IsEmpty(MatriFormSBID.SSID,'text')){
		show_menu('2', this, '121'); subTabTimeout('menu_block2','tab1','2'); show_hide_sbid("show");
		alert("Please enter Matrimony ID.");
		return false;
	}
	else{ return true; }
}

function frmvalidbyid(){
	if(!validateById()){ return false; }
	document.MatriFormSBID.action="http://"+DOMAINARRAY['domainmodule']+"/profiledetail/viewprofile.php";
	return true;
}
