var loggedInPid;
var startTimeL2=0;
var common_error='<span style="color:#FF0000"><img src="'+SITE_URL+'/profile/images/iconError_16x16.gif"><b>An error has occurred! We will be correcting this problem at the earliest. Kindly check back later.</b></span>';
//This variable is used to hide the layer that are not required to show, such as more option layer, save search option etc.
var common_check=0;
var function_to_call=""
var same_function_call=0
var imediate=0
var from_outside=0
var on_click_force=0
var logged_in_username=""
//This variable will change only after confirmation done by user.
var allow_decline=0;
function for_confirmation(request_for,who_is,user_name,index)
{
	var url_str="";
	if(request_for=='DECLINE')
	{
		if(who_is=='SENDER')
			url_str="&status=C";
		else
			url_str="&status=D";
		url_str=url_str+"&request_for=DECLINE&other_username="+user_name+"&index="+index;
		url_str=SITE_URL+"/profile/conf_dec_can.php?temp=1"+url_str+"&height=300&width=512";
		tb_show("",url_str,"");
	}
}


//Here close_func variable signifies the function that to be called for closing the layer.
function set_focus_on_anchor(name_of_anchor)
{
        var loc_str=document.location.href;
        var regExpr=/#[a-z\_A-Z0-9]*/;
	
        loc_str=loc_str.replace(regExpr,"");
        document.location.href=loc_str+name_of_anchor

}
function set_onclick_on_all_link()
{
	/*var all=document.getElementsByTagName("a");
	for(var i=0;i<all.length;i++)
	{
	        if(!all[i].onclick && all[i].className!='thickbox' )
        	{
			//all[i].attachEvent("onclick","check_window('no_onclick')");
                	all[i].onclick=function(){check_window('no_onclick');};
        	}
	}
	*/
                        
}
function dID(arg)
{
	return document.getElementById(arg);

}
function check_window(close_func)
{
	//This function is used to return value false if a tag is clicked.
	if (typeof(close_func)=='undefined' || typeof(close_func)=='object' )
	{
		if(common_check==1 && function_to_call!=""  && imediate==0)
		{
			eval(function_to_call);
		}
		//Added only this condition to hide the layer by just click on outside.
		if(imediate==1)
			imediate=0;

		if(!e) var e=window.event;	
		if(!e) var e=close_func;
		var tg = (window.event) ? e.srcElement : e.target;

		//Prevent thickbox layer to reload the page.
		if(tg.className=='thickbox')
			return false;

		if(tg.nodeName=='INPUT')
		{
			if(tg.value=="Express Interest - Free")
                                return false;
			tg2=tg.parentNode;
			if(tg2.nodeName!='A')
				return true;
		}
		if(tg.nodeName=='DIV' || tg.nodeName=='SPAN' || tg.nodeName=='TD' || tg.nodeName=='TR' || tg.NodeName=='TABLE' || tg.nodeName=='IMG')
		{
			tg=tg.parentNode;
			if(tg.nodeName=='A' && !tg.onclick)
				return true;
			if(tg.nodeName=='A')
				return false;
			imediate=0;
		}
		else if(tg.nodeName=='A')
		{
			if(!tg.onclick)
				return true;
			return false;
		}
	}

	if(typeof(close_func)!='object' && typeof(close_func)!='undefined')
	{//alert(common_check+"  "+function_to_call+" "+close_func);
		if(common_check==1 && function_to_call!="" && function_to_call!=close_func )
		{
			eval(function_to_call);

		}
	/*	var e=event;
		if(!e)
			var e=window.event
		e.cancelBubble=true;*/
		//var e=window.event;
		//e.stopPropagation();

		
	}
        if(typeof(close_func)!='object' && typeof(close_func)!='undefined')
        {
		if(close_func==function_to_call)
			same_function_call=1;
                imediate=1
                return 1
        }
	if(imediate)
	{
		imediate=0
		return false;
	}
	if(same_function_call)
	{
		same_function_call=0;
		return false;
	}	
	if(common_check==1)
	{
		if(function_to_call)
			eval(function_to_call);
	}
	return true;
}
function send_ajax_request(url,before_call_func,after_call_func,method)
{
	 if(url.indexOf(SITE_URL)==-1)
                url=SITE_URL+"/profile/"+url;
	if(url.indexOf("single_contact_aj.php")!=-1 || url.indexOf("AjaxContact.php")!=-1)
		method="POST";
        var ajaxRequest;  // The variable that makes Ajax possible!
	result=""
	if(method=="")
		method="GET";
        try
        {
                // Opera 8.0+, Firefox, Safari
                ajaxRequest = new XMLHttpRequest();
        }
        catch (e)
        {
                // Internet Explorer Browsers
                try
                {
                        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e)
                {
                        try
                        {
                                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (e)
                        {
                                // Something went wrong
                                alert("Your browser broke!");
                                return false;
                        }
                }
        }
        // Create a function that will receive data sent from the server
        ajaxRequest.onreadystatechange = function()
        {
                if(ajaxRequest.readyState == 4)
                {
			if(ajaxRequest.status==200)
			{
				//Please defined this variable in the script tag where this send_ajax function is called, this is required since result is required at function called below
				result= ajaxRequest.responseText;
				if(after_call_func)
					eval(after_call_func+"()");
				//Nikhil setting onclick on every a tagname
        	                //set_onclick_on_all_link();
        	        }
			else
			{
				result="A_E";
				if(after_call_func)
                                        eval(after_call_func+"()");
			}
                }
        }
	if(method=='POST')
	{
		var send_params = url.replace(/^[^\?]+\??/,'');
		var check_url=url.replace(/[\?].+/,'');
		//send_params=send_params.substr(1,send_params.length);
		ajaxRequest.open("POST",check_url, true);
                ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                ajaxRequest.setRequestHeader("Content-length", send_params.length);
                ajaxRequest.setRequestHeader("Connection", "close");
                ajaxRequest.send(send_params);
	}
	else
	        ajaxRequest.open("POST",url, true);
	if(before_call_func)
		eval(before_call_func+"()");

	//This is required only for those ajax request that send data through GET
	if(method!='POST')
		ajaxRequest.send(null);
}
function checkemail(emailadd)
{
        var ce_results = false;
        var theStr = new String(emailadd);
        var index = theStr.indexOf("@");
        if (index > 0)
        {
        var pindex = theStr.indexOf(".",index);
        if ((pindex > index+1) && (theStr.length > pindex+2))
                ce_results = true;
        }

        return ce_results;
}
var show_anchor=1;
function show_layer(to_show,to_hide,to_change,to_roll,from_actual)
{
	if(from_actual)
		show_anchor=0;
	else
		show_anchor=1;
	if(dID(to_show))
	{
		dID(to_show).style.display='inline';
		if(to_show=='show_express')
		{
			if(show_anchor)
			{
				var loc_str=document.location.href;
				var regExpr=/#[a-z\_A-Z]*/;
			        loc_str=loc_str.replace(regExpr,"");
	               		document.location=loc_str+"#express_link"
			}
		}
		if(dID(to_change))
		{
			dID(to_change).className="cont_open_tab";
		}
	}
	if(dID(to_hide))
	{
		dID(to_hide).style.display='none';
		if(dID(to_roll))
                {
                        dID(to_roll).className="cont_close_tab";
                }
	}
}
function writeafterSave(pid)
{
        var str,loop=1;

        str='<span style="visibility:hidden;"><img src="'+SITE_URL+'/profile/images/icon_rect.gif"> <a href="#" onclick="save_search_options(\'show\','+pid+');return false;" class="blink">My saved searches</a></span><IFRAME id="iframeshim"  src="" style="display: inline; left: -60px; top: 32px; z-index: 2; position: absolute; width: 190px; height: 78px;filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);" frameBorder="0" scrolling="no"></IFRAME><span style="position:absolute;left:-70px;z-index:1000;top:0px">';
        str+='<div class="lf" style="width:188px;"><div class="m_saved_topbg"><div class="t12 b" style="padding:4px 0 0 55px;"><img src="'+SITE_URL+'/profile/images/dw_blk_arrow.gif"> My saved searches</div></div><div class="m_saved_hrbg" style="padding:17px 15px; width:150px; line-height:20px">';
        str+='<span id="my_save_search_id">';
        str+='<div style="text-align:center"><img src="'+SITE_URL+'/profile/images/ajax-loader.gif"><\/div>';
        str+='</span>';
        str+='<div style="text-align:right;padding-top:4px;"><a href="#" onclick=\'save_search_options("hide",'+pid+');return false;\' class="t12 blink b">Close[x]</a></div></div><div class="m_saved_footerbg"></div></div></span>';
        mysavesearches_ajaxValidation(pid);
        return str;
}
function save_search_options(what,pid)
{
        var close_save1="<img src='"+SITE_URL+"/profile/images/icon_rect.gif'>\<a href='#' class=\"blink\" onclick=\"save_search_options('show',"+pid+");return false;\"> My saved searches</a>";
	
        if(what=='show')
        {
		check_window('save_search_options(\'hide\',\''+pid+'\')');
		common_check=1;
		function_to_call="save_search_options('hide',"+pid+")";
                dID("save_search_option").innerHTML=writeafterSave(pid);
        }
        else
        {
		common_check=0;
		function_to_call="";
		
	        dID("save_search_option").innerHTML=close_save1;
	}
}
function createNewXmlHttpObject()
{
        req = false;
        if(window.XMLHttpRequest)
        {
                try
                {
                        req = new XMLHttpRequest();
                }
                catch (e)
                {
                        req = false;
                }
        }
        else if(window.ActiveXObject)
        {
                try
                {
                        req = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e)
                {
                        try
                        {
                                req = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (e)
                        {
                                req = false;
                        }
                }
        }
        return req;
}
function createNewXmlHttpObject1()
{
        req1 = false;
        if(window.XMLHttpRequest)
        {
                try
                {
                        req1 = new XMLHttpRequest();
                }
                catch (e)
                {
                        req1 = false;
                }
        }
        else if(window.ActiveXObject)
        {
                try
                {
                        req1 = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e)
                {
                        try
                        {
                                req1 = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (e)
                        {
                                req1 = false;
                        }
                }
        }
        return req1;
}

function mysavesearches_ajaxValidation(pid)
{
        var req = createNewXmlHttpObject();
	loggedInPid=pid;

        var to_post = "list_save=1 & pid=" + pid;
        if(pid)
        {
                req.open("POST","/P/save_search.php",true);
                req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
                req.send(to_post);
                req.onreadystatechange = mysavesearches_checkXmlHttpStatus;
        }
        else
        {

        }
}

function mysavesearches_checkXmlHttpStatus()
{
         var str='';
        if (req.readyState != 4)
        {
                return;
        }
        if (req.status == 200)
        {
                var got_response = req.responseText.split("$");
                if(got_response[0]!="")
                {
                        if(got_response[0]!='A_E')
                        {
                                if(got_response[0])
                                        var gotresponsestr=got_response[0].split("#");
                                if(got_response[1])
                                        var gotresponsestr1=got_response[1].split("#");
                                if(got_response[2])
                                        var gotresponsestr2=got_response[2].split("#");
                        }

                        if(got_response[0]=='A_E')//ajax Error
                        {
                                str+='<span style="color:#FF0000"><img src="'+SITE_URL+'/profile/images/iconError_16x16.gif"><b>An error has occurred! We will be correcting this problem at the earliest. Kindly check back later.</b></span>';
                        }
                        else
                        {
                        if(got_response[0])
                                str+='<a href="'+SITE_URL+'/profile/search.php?mysearchid=' + gotresponsestr[1] + '"class="blink">' + gotresponsestr[0] + '</a><br>';
                        if(got_response[1])
                                str+='<a href="'+SITE_URL+'/profile/search.php?mysearchid=' + gotresponsestr1[1] + '"class="blink">' + gotresponsestr1[0] + '</a><br>';
                        if(got_response[2])
                                str+='<a href="'+SITE_URL+'/profile/search.php?mysearchid=' + gotresponsestr2[1] + '"class="blink">' + gotresponsestr2[0] + '</a><br>';
                        }
                        dID("my_save_search_id").innerHTML=str;
                        return ;
                }
                else
                {

                }
        }
        else
        {
                return;
        }
}

function Get_Cookie( name )
{
        var start = document.cookie.indexOf( name + "=" );
        var len = start + name.length + 1;
        if ( ( !start ) &&
        ( name != document.cookie.substring( 0, name.length ) ) )
        {
        return null;
        }
        if ( start == -1 ) return null;
        var end = document.cookie.indexOf( ";", len );
        if ( end == -1 ) end = document.cookie.length;
        return unescape( document.cookie.substring( len, end ) );
}

function Set_Cookie( name, value, days, path, domain, secure ) 
{
	
	var date = new Date();
	if(days)
	{
		//Make cookie for day
		//date.setTime(date.getTime()+(days*24*60*60*1000));
		//Make cookie for hour
		//date.setTime(date.getTime()+(days60*60*1000));
		//Make cookie for minute
		date.setTime(date.getTime()+(days*60*1000));
		
	}

        document.cookie = name + "=" +escape( value ) +
        ( ( days ) ? ";expires=" + date.toGMTString() : "" ) + 
        ( ( path ) ? ";path=" + path : "" ) + 
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
}
function MM_openBrWindow(theURL,winName,features)
{
window.open(theURL,winName,features);
}

if(typeof SITE_URL=="undefined")
                var SITE_URL="http://"+top.location.host;
var after_searchbyid='<span style="visibility:hidden;width:200px"><img src="'+SITE_URL+'/profile/images/icon_rect.gif"> <a href="#" onclick="search_by_id(\'show\');return false;" class="blink"> Search by profile id</a></span><IFRAME id="iframeshim"  src="" style="display: inline; left: -60px; top: 32px; z-index: 2; position: absolute; width: 270px; height: 78px;filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);" frameBorder="0" scrolling="no"></IFRAME><span style="position:absolute;left:-70px;z-index:1000;top:0px"><div class="lf" style="width:188px;" ><div class="sr_display_top" style="z-index:1000;" ><div class="t12 b" style="padding:4px 0 0 75px;"><img src="'+SITE_URL+'/profile/images/dw_blk_arrow.gif"> Search by profile id</div></div><div class="sr_display_hr" style="padding:10px 15px; line-height:20px"><input type="textbox" id="SEARCH_BY_USERNAME" value="" class="pd" style="width:140px" onkeydown="javascript:check_enter(\'search_by_username()\',event)">&nbsp;&nbsp;&nbsp;<input type="button" style="width: 60px;" value="Search" class="b green_btn" onclick="javascript:search_by_username()"/></div><div  class="sr_display_hr" style="padding: 10px 15px;text-align:center" ><a href="#" onclick="search_by_id(\'hide\');return false;" class="blink b">Close[X]</a></div><div class="sr_display_footer"></div> </div></span>';

var close_searchbyid=' <img src="'+SITE_URL+'/profile/images/icon_rect.gif"> <a href=# onclick="search_by_id(\'show\');return false;" class="blink"> Search by profile id</a>';
function check_enter(java_func,e)
{
	var numCode=e.keyCode;
	if(numCode==13)
	{
		if(java_func!="")
			eval(java_func);
	}
}
function search_by_id(what)
{
        if(what=="show")
        {
		check_window('search_by_id(\'hide\')');
	        dID("search_by_id").innerHTML=after_searchbyid;
		dID("SEARCH_BY_USERNAME").focus();
		common_check=1;
		function_to_call="search_by_id('hide')";
	}
        else
        {
		common_check=0;
		function_to_call="";
	        dID("search_by_id").innerHTML=close_searchbyid;
	}
}


function search_by_username()
{
        //check is navigator is set

         if(typeof NAVIGATOR=="undefined")
		var NAVIGATOR='';
	if(typeof SITE_URL=="undefined")
		var SITE_URL="http://"+top.location.host;

        search_username_id=dID("SEARCH_BY_USERNAME");
	
	var url_for_profile=SITE_URL+'/profile/viewprofile.php?search=1&username='+search_username_id.value+'&'+NAVIGATOR+'&overwrite=1';
        if(search_username_id.value==logged_in_username && search_username_id.value!="" && logged_in_username!="")
        {
                window.open(url_for_profile,"SAME_USERNAME",'width=800,height=600,status=1,scrollbars=1,resizable=yes');
        }
        else
                window.location=url_for_profile;

        search_by_id('hide');
}

if(typeof SITE_URL=="undefined")
                var SITE_URL="http://"+top.location.host;

after_moreclick='<span style="visibility:hidden;width:200px"> <img src="images/icon_rect.gif"> <a class=blink" href=# onclick="javascript:show_more_options(\'show\')">More Options</a></span><IFRAME id="iframeshim"  src="" style="display: inline; left: -60px; top: 32px; z-index: 2; position: absolute; width: 140px; height: 78px;filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);" frameBorder="0" scrolling="no"></IFRAME><span style="position:absolute;left:-74px;top:-4px;z-index:1000"><div class="lf" style="width:188px;"><div class="more_topbg"><div class="blink b" style="padding:4px 0 0 75px;"><img src="images/icon_rect.gif"> <a href="#" class="blink">More Options</a></div></div><div class="more_hrbg" style="padding:10px 15px; width:150px; line-height:20px"><a href="'+SITE_URL+'/profile/advance_search.php" class="blink">Advanced Search</a><br><!--a href="#" class="blink">Members looking for me</a><br--><a href="'+SITE_URL+'/profile/search.php?MEM_LOOK=1" class="blink">Members I am looking for</a></div><div  class="more_hrbg" style="padding: 5px 15px; width: 150px;text-align:center" ><a href="javascript:show_more_options(\'hide\')" class="blink b">Close[X]</a></div><div class="more_footerbg"></div>        </div></span>';
close_moreclick=' <img src="images/icon_rect.gif"> <a class=blink" href="javascript:show_more_options(\'show\')">More Options</a>';


function show_more_options(what)
{
        if(what=="show")        
        {
		common_check=1;
                function_to_call="show_more_options('hide')";
	        dID("more_option").innerHTML=after_moreclick;
	}
        else
        {
		common_check=0;
                function_to_call="";
	        dID("more_option").innerHTML=close_moreclick;
	}
}


function redirect(prev_url)
{
        if(prev_url!="")
                document.location=prev_url;
        return false;
}
function check_thickbox_command()
{
	var arr=new Array;
        var idd="";
	var after_call="";
	if(dID("AFTER_LOGIN_CALL"))
		after_call=dID("AFTER_LOGIN_CALL").value;
	
        if(dID("CALL_THICK"))
        {
                arr[0]=dID("CALL_THICK").value;
                arr[1]=dID("id_checked").value;

        }
        if(arr[0] || after_call)
        {
                        var checkboxes=arr[1].split("-----");
                        for(var i=0;i<checkboxes.length;i++)
                        {
                                idd=checkboxes[i];
                                if(dID(idd))
                                        dID(idd).checked=true;

                        }
		if(after_call)
		{
			var url_thick=unescape(arr[0]);
        	        if(url_thick.length>10)
                	        tb_show("",url_thick,"");
			eval(after_call);
		}
		else
		{
			var url_thick=unescape(arr[0]);
        	        if(url_thick.length>10)
                	        tb_show("",url_thick,"");
		}
        }

        if(startTimeL2)//TRACKING
        {
        var endTimeL = (new Date()).getTime();
        var differnceDNS=startTimeL-CLICKTIME;
        var difference = endTimeL - startTimeL;
        var differenceBody = startTimeL2 - startTimeL;
        var differenceHead = startTimeL1 - startTimeL;
        var to_post = "difference=" + difference + "&headTime=" + differenceHead + "&bodyTime=" + differenceBody + "&pagExec=" + pagExec + "&searchid=" + searchidL + "&differnceDNS=" + differnceDNS + "&sphinxS=" + sphinxS + "&nikhil=" + startTimeL + "&ankit=" + CLICKTIME;
        var req = createNewXmlHttpObject();
        req.open("POST","/P/searchTrack.php",true);
        req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        req.send(to_post);
        }
}

function initializeBody() 
{
	if(!dID("abc1"))
		return;
        var dareDiv = dID("abc1");
        var wheatDiv = dID("abc2");
        dareDiv.onmouseover = colorIt;
        dareDiv.onmouseout = uncolorIt
        wheatDiv.onmouseover = colorIt;
        wheatDiv.onmouseout = uncolorIt;

}
function colorIt() 
{
        dID("abc2").style.visibility = "visible";
        dID("abc1").style.visibility = "hidden";
}
function uncolorIt() 
{
        dID("abc1").style.visibility = "visible";
        dID("abc2").style.visibility = "hidden";
}
function get_present_date()
{
        var dt=new Date();
        var day=dt.getDate();
        var monthIndex=dt.getMonth();
        var year=dt.getFullYear();
        var month_name=new Array();
        month_name[0]="Jan";
        month_name[1]="Feb";
        month_name[2]="Mar";
        month_name[3]="Apr";
        month_name[4]="May";
        month_name[5]="Jun";
        month_name[6]="Jul";
        month_name[7]="Aug";
        month_name[8]="Sep";
        month_name[9]="Oct";
        month_name[10]="Nov";
        month_name[11]="Dec";
        var month=month_name[monthIndex];
        var complete_date=day+" "+month+" "+year;
        return complete_date;
}

function includeCSSfile(href)
{
        var head_node = document.getElementsByTagName('head')[0];
        var link_tag = document.createElement('link');
        link_tag.setAttribute('rel', 'stylesheet');
        link_tag.setAttribute('type', 'text/css');
        link_tag.setAttribute('href', href);
        link_tag.setAttribute('name', 'for_home');
        head_node.appendChild(link_tag);
}
function reload_messages(draft_id,draft_name,draft_mes)
{
        var change_id=draft_id.value;
        if(typeof(MES)!='undefined')
		MES[change_id]=draft_mes.value.replace("<br />","\n");

	if(typeof(decline)!='undefined')
	       decline[change_id]=draft_name.value.replace("<br />","\n");

        if(typeof(accept)!='undefined')
		accept[change_id]=draft_name.value.replace("<br />","\n");
}
function call_dp(profileid)
{
	
	if(dID(profileid))
	{
		var id_hidden=dID(profileid).value;
		id_hidden=id_hidden+"&after_login_call="+escape("change_tab(dID('horoscope'),'Horoscope')")
		document.location=id_hidden;
	}
	return false;
}
function up_launch(receiversid, sendersid,senderusername,receiverusername,threadname,status)
{
if(senderusername>receiverusername)
threadname=senderusername+"_"+receiverusername;
else
threadname=receiverusername+"_"+senderusername;
threadname=up_replaceAlpha(threadname);
window.open('http://198.104.137.142/profile/chatwindow.php?receiversid='+receiversid+'&sendersid='+sendersid+'&senderusername='+senderusername+'&receiverusername='+receiverusername+"&status="+status+"&checksum="+prof_checksum,threadname,'width=342,height=274,status=1,scrollbars=0,resizable=no');
}

function up_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;

}
function astro_icons()
{
        var docF=document.getElementsByTagName("input");
        var pstring="";
        for(var i=0;i<docF.length;i++)
        {
                if(docF[i].name.match("horo_astro"))
                {
                        pstring1=docF[i].value;
                        pstring=pstring+pstring1+"@";
                }
        }
        var request_url = SITE_URL+"/profile/issue_2472.php?profileid=&checksum="+prof_checksum+"&compstring="+pstring;
        send_ajax_request(request_url,"","after_astro_call","GET");
}
function after_astro_call()
{
        var res = result;
        var x = res.substr(0).split("/>");
        for (var j=0; j<(x.length-1); j++)
        {
                if(x[j].charAt(0)==">")
                        x[j]=x[j].substr(1,x[j].length);
                var y = x[j].split(":");
                if(typeof(y[2]) != "undefined")
                {
                        var Guna_str = "Guna_"+y[0];

                        var Guna  = y[2].substr(0,4)+"/36";
                        var Lg = y[3].substr(0,2);
                        var Su = y[4].substr(0,2);
                        var Me = y[5].substr(0,2);
                        var Ju = y[6].substr(0,2);
                        var Sa = y[7].substr(0,2);

                        var lagan = "LAGAN_ID_"+y[0];
			var main_lagan="MAIN_"+lagan;
                        var imgs=new Array;
                        var titles=new Array;
                        if(Lg == 1)
                        {
                                imgs[0]="lagan_p.jpg";
                                titles[0]="Lagan Favourable"
                        }
                        else if(Lg == -1)
                        {
                                imgs[1]="lagan_m.jpg";
                                titles[1]="Lagan Unfavourable"
                        }
                        if(Su == 1)
                        {
                                imgs[2]="sun_p.jpg"
                                titles[2]="Sun Favourable"
                        }
                        else if(Su == -1)
                        {
                                imgs[3]="sun_m.jpg";
                                titles[3]="Sun Unfavourable";
                        }
                        if(Me == 1)
                        {
                                imgs[4]="murcury_p.jpg";
                                titles[4]="Mercury Favourable"
                        }
                        else if(Me == -1)
                        {
                                imgs[5]="murcury_m.jpg";
                                titles[5]="Mercury Unfavourable"
                        }
                        if(Ju == 1)
                        {
                                imgs[6]="jupitar_p.jpg";
                                titles[6]="Jupitor Favourable"
                        }
                        else if(Ju == -1)
                        {
                                imgs[7]="jupitar_m.jpg";
                                titles[7]="Jupitor Unfavourable"
                        }
                        if(Sa == 1 || Sa == "1")
                        {
                                imgs[8]="saturn_p.jpg";
                                titles[8]="Saturn Favourable"
                        }
                        else if(Sa == -1)
                        {
                                imgs[9]="saturn_m.jpg";
                                titles[9]="Saturn Unfavourable"
                        }


                        if(Guna)
                        {
                                var img_str="";
                                var IMG_URL="http://ser4.jeevansathi.com/profile/images/";
                                for(var i=0;i<imgs.length;i++)
                                {
                                        if(imgs[i])
                                                img_str=img_str+"<Td><img src='"+IMG_URL+imgs[i]+"' title='"+titles[i]+"' ></td>";
                                }
                                img_str=img_str+"<td>"+Guna+"</td>";
                                if(dID(lagan))
				{
					dID(lagan).innerHTML="<table cellspacing=0 cellpadding=3 border=0 style=\"padding:0;margin:0\"><TR>"+img_str+"</tr></table>";
					if(dID(main_lagan))
						dID(main_lagan).style.marginTop="-50px";
				}
                        }

                }
        }
}
var from_view_similar=0;
function save_draft(view_sim)
{
	var s_draft_show="s_draft_show";
	var s_draft_id="s_draft_id";
	var s_draft_name="s_draft_name";
	var s_draft_mes="s_draft_mes";
	from_view_similar=0;
	if(typeof(view_sim)!='undefined')
	{
		from_view_similar=1;
		s_draft_show="s_draft_show_page";
		s_draft_id="s_draft_id_page";
		s_draft_name="s_draft_name_page";
		s_draft_mes="s_draft_mes_page";
	}
        var draft_id='';
        var draft_name='';
        var draft_mes='';
        var id_name='';
        var draft_main=dID(s_draft_show);

        if(dID(s_draft_id))
                draft_id=dID(s_draft_id);
        if(dID(s_draft_name))
                draft_name=dID(s_draft_name);
        if(dID(s_draft_mes))
                draft_mes=dID(s_draft_mes);
        if(draft_name)
        {
                reload_messages(draft_id,draft_name,draft_mes);
                if(draft_name.value=="")
                {
                        draft_name.focus();
                        return 0;
                }
                else 
                {
                        if(draft_id)
                        {
                                if(draft_id.value=="")
                                {
                                        draft_id.focus();
                                        return 0;
                                }
                                id_name=draft_id.value;
                        }

                }
                draftname=escape(draft_name.value);
                real_mes=escape(draft_mes.value);
                data_to_send=SITE_URL+"/profile/SaveDraft.php?DRAFT_NAME="+draftname+"&DRAFT_ID="+id_name+"&DRAFT_MES="+real_mes+"&D_STATUS="+d_status;
                draft_main.innerHTML=dra_loader;
		send_ajax_request(data_to_send,"","after_save_draft","POST");
            //    sendAjaxRequestForContact("SAVE_DRAFT",data_to_send);
        }
                

}
function after_save_draft()
{
	var s_draft_show="s_draft_show";
	if(from_view_similar)
	{
		s_draft_show="s_draft_show_page";
	}
	var draft_main=dID(s_draft_show);
	if(result=='A_E')
	{
		draft_main.innerHTML="<span>"+common_error+"</span>";
	}
	if(result.substr(0,5)=='ERROR')
	{
		draft_main.innerHTML="<span>"+result.substr(6,result.length)+"</span>";
	}
	else
	{
		draft_main.innerHTML=dra_end1+result+dra_end2;
	}
}
function disable_button(id_name,upto)
{
                for(i=0;i<upto;i++)
                {
                        if(eval("dID('"+id_name+i+"')"))
                                eval("dID('"+id_name+i+"').style.display='none'");
                }
}
function enable_button(id_name,upto)
{
        for(i=0;i<upto;i++)
                {
                        if(eval("dID('"+id_name+i+"')"))
                                eval("dID('"+id_name+i+"').style.display='inline'");
                }
}
function show_save(bool,from_sim)
{
	var but_id="but_id";
	var mes_id="mes_";
	if(typeof(from_sim)!='undefined')
	{
		var but_id="but_id_page";
		var mes_id="page_mes_";
	}
        if(bool)
        {
		if(dID(but_id))
			dID(but_id).style.display='inline';
                enable_button(mes_id,2);
        }
        else
        {
	        disable_button(mes_id,2);
		if(dID(but_id))
			dID(but_id).style.display='none';
	}
}
function red_view_similar(var_data)
{
	if(var_data)
	{
			var all_data=var_data.split(":");

                        var contact_id=all_data[1];
                        var sim_username=all_data[2];
                        var type_of_con=all_data[3];
                        var from_search=0;
                        if(dID("from_search"))
                                from_search=1;
			var html_form="<form name=fr1 id=vsp method=POST action='/profile/view_similar_profile.php?&draft_name="+draft_id+"&contact="+contact_id+"&SIM_USERNAME="+sim_username+"&stype=CN&"+navig+"&type_of_con="+type_of_con+"&from_search="+from_search+"'><input type='hidden' name='MESSAGE' value='"+text_message+"'></form>";
			document.body.innerHTML=html_form+document.body.innerHTML;
			dID("vsp").submit();
//                        var url_for_contact="/profile/view_similar_profile.php?&draft_name="+draft_id+"&contact="+contact_id+"&SIM_USERNAME="+sim_username+"&MESSAGE="+text_message+"&stype=CN&"+navig+"&type_of_con="+type_of_con+"&from_search="+from_search;
  //                      document.location.href=url_for_contact;
                        tb_remove();
	}
}
