//# $Id: glusr-header-0.1.js 21098 2010-08-31 09:35:34Z daksh $
//# $HeadURL: http://qmail1/svn/im-sw/indiamart-trade/trunk/main/glusr-header-0.1.js $

var value = "";
value = readCookie('v4iilex');

var url = document.URL;
var redirect = "";

if(url.match('signout.html'))
{
	redirect = '/';
}
else
{
	redirect = escape(url);
}

function readCookie(name)
{
	// new code... delete above original code if no problem is seen on any pages
	var search = name + "="
	if (document.cookie.length > 0)
	{ 
		offset = document.cookie.indexOf(search)
		if (offset != -1) // if cookie exists
		{ 
			offset += search.length
			end = document.cookie.indexOf(";", offset)	// set index of beginning of value
			if (end == -1) end = document.cookie.length	// set index of end of cookie value
			return unescape(document.cookie.substring(offset, end))
		}
	}

	//--------------------------------------------------------------
	// if v4iilex not found.. not set.. then try for v4iil once.. 
	if (name == 'v4iilex')
	{
			return readCookie('v4iil');
	}
	//--------------------------------------------------------------

	return "";
}


function getparam(key)
{
	if( (cookie = readCookie("v4iilex")) > "")		//alert(readCookie("v4iilex"));
	{
		var val = "|"+cookie+"|";
		var pattern = new RegExp(".*?\\|"+key+"=([^|]*).*|.*");
		return val.replace(pattern, "$1");
	}
}

if(value == null || value == "")
{
	document.write('<UL CLASS="q_sq"><LI><A HREF="http://my.indiamart.com/cgi/glusr-check.mp?login=true&modid=MY&redirect='+redirect+'" TARGET="_top" CLASS="q_p1 q_p9" rel="nofollow">Sign In</A></LI><LI><A HREF="http://my.indiamart.com/cgi/glusr-reg1.mp?action=newreg1&modid=MY&redirect='+redirect+'" TARGET="_top" CLASS="q_p10 q_p9 q_bl9" rel="nofollow">Join Free</A></LI><LI><A HREF="http://my.indiamart.com/" TARGET="_top" CLASS="q_p10 q_p9 q_bl9">My IndiaMART</A></LI></UL>');
}
else
{
	var username = getparam('name');
	if (username == null || username == "")
	{
		username = '<UL class="q_sq"><LI><A HREF="http://my.indiamart.com/cgi/glusr-check.mp?logoff=true&modid=MY&redirect='+redirect+'" target="_top" CLASS="q_p1 q_p9" rel="nofollow">Sign Out</A></LI><li><A HREF="http://my.indiamart.com/" target="_top" CLASS="q_p10 q_p9 q_bl9">My IndiaMART</A></LI></UL>';
	}
	else
	{
		username = '<UL class="q_sq"><LI><b class="q_fz1 q_p2 q_p14"><span class="q_cr3">Welcome: </span>'+username+'</b><A HREF="http://my.indiamart.com/cgi/glusr-check.mp?logoff=true&modid=MY&redirect='+redirect+'" target="_top" CLASS="q_p1 q_p9 q_bl9" rel="nofollow">Sign Out</A></LI><li><A HREF="http://my.indiamart.com/" target="_top" CLASS="q_p10 q_p9 q_bl9">My IndiaMART</A></LI></UL>';
	}
	document.write(username);
}

function tollfree() 
{
	var myDate = new Date();
	var gmt = -myDate.getTimezoneOffset()/60; 
	if(gmt == 5.5){
	document.getElementById('tollfree').innerHTML = '<b>Call Toll-Free:</b> 1-800-200-4444';
	}else{
	document.getElementById('tollfree').innerHTML = '<b>Helpline:</b> +91-9696969696';
	}
}

// TOP RIGHT MENU

var idn = '';

function wh(id)
{	idn = id;
	document.getElementById(id).style.backgroundColor='#FFF';
}
var cssmenuids=["cssmenu1"]
var csssubmenuoffset=-1
var abc ='';

function createcssmenu2()
{
	for (var i=0; i<cssmenuids.length; i++)
	{
		var ultags=document.getElementById(cssmenuids[i]).getElementsByTagName("ul");
		for (var t=0; t<ultags.length; t++)
		{
			abc = document.body.clientWidth;
			abc = abc-995;
			abc = abc/2;
			abca = abc+765;
			abc = abc+715;
			ultags[t].style.top=ultags[t].parentNode.offsetHeight+csssubmenuoffset+"px";
			var spanref=document.createElement("span");
			spanref.className="arrowdiv";
			spanref.innerHTML="";
			ultags[t].parentNode.getElementsByTagName("a")[0].appendChild(spanref);
			ultags[t].parentNode.onmouseover=function()
			{
				this.style.zIndex=100;
				this.getElementsByTagName("ul")[0].style.visibility="visible";
				this.getElementsByTagName("ul")[0].style.zIndex=100;
				this.getElementsByTagName("ul")[0].style.left="0px";
				document.getElementById('m1').style.marginLeft=abc+"px";
				document.getElementById('m2').style.marginLeft=abca+"px";
				var nAgt = navigator.appVersion;
				var patt = /MSIE 6.0/;
				if(patt.test(nAgt))
				{
					document.getElementsByTagName('select')[0].style.display="none";
				}
				document.getElementById('s1').style.backgroundColor='';
				if(document.getElementById(idn))
				{
					document.getElementById(idn).style.backgroundColor='#FFF';
				}
			}
			ultags[t].parentNode.onmouseout=function()
			{
				this.style.zIndex=0;
				this.getElementsByTagName("ul")[0].style.visibility="hidden"
				var nAgt = navigator.appVersion;
				var patt = /MSIE 6.0/;
				if(patt.test(nAgt))
				{
					document.getElementsByTagName('select')[0].style.display="";
				}
				this.getElementsByTagName("ul")[0].style.zIndex=100;
				if(document.getElementById(idn))
				{
					document.getElementById(idn).style.backgroundColor='';
				}
			}
		}
	}
}

if (window.addEventListener)
	window.addEventListener("load", createcssmenu2, false);
else if (window.attachEvent)
	window.attachEvent("onload", createcssmenu2);


function srchb()
{
	var option = document.searchForm.searchfor;
	var field = document.searchForm.ss;

	if(option.value == "comp")
	{
		if (field.value=='Enter Product / Company Name to Search ...')
		{
			field.value = '';
			field.style.color = "#000000";
		}
		else if (field.value=='')
		{
			field.value = 'Enter Product / Company Name to Search ...';
			field.style.color = "#626262";
		}
	}
	else if(option.value == "product")
	{
		if (field.value=='Enter Product / Company Name to Search ...')
		{
			field.value = '';
			field.style.color = "#000000";
		}
		else if (field.value=='')
		{
			field.value = 'Enter Product / Company Name to Search ...';
			field.style.color = "#626262";
		}
	}
	else if(option.value == "tenders")
	{
		if (field.value=='Enter keyword / company name to search preferred tenders ...')
		{
			field.value = '';
			field.style.color = "#000000";
		}
		else if (field.value=='')
		{
			field.value = 'Enter keyword / company name to search preferred tenders ...';
			field.style.color = "#626262";
		}
	}
	else if(option.value == "offer")
	{
		if (field.value=='Enter Product / Service Offers to Search ...')
		{
			field.value = '';
			field.style.color = "#000000";
		}
		else if (field.value=='')
		{
			field.value = 'Enter Product / Service Offers to Search ...';
			field.style.color = "#626262";
		}
	}
	else if(option.value == "leads")
	{
		if (field.value=='Enter Product / Service Buy Leads to Search ...')
		{
			field.value = '';
			field.style.color = "#000000";
		}
		else if (field.value=='')
		{
			field.value = 'Enter Product / Service Buy Leads to Search ...';
			field.style.color = "#626262";
		}
	}
}

function CheckDataSearch(Form)
{
	var re = /(Enter\s+.*?Search)/i;

	if (Form.ss.value.match( re ))
	{	
		var found = Form.ss.value.replace('...', ' ');
		found = found.replace(/\s+$/g, '');
		alert('Please ' + found + '.');
		Form.ss.focus();
		return false;
	}
	Form.ss.value = Form.ss.value.replace(/[^a-zA-Z0-9 ]/g, ' ');
	Form.ss.value = Form.ss.value.replace(/^\s+/g, '').replace(/\s+$/g, '');
	while(Form.ss.value.indexOf('  ')>0){
		Form.ss.value = Form.ss.value.replace('  ',' ');
	}
	
	var temp=Form.ss.value.replace(/\s/g, '');
	if (temp.length < 3){
		alert("Enter at least three characters for search.");
		Form.ss.focus();
		return false;
	}
	else
	{
		var str = Form.ss.value.replace(/\s/g, '+');
		if(Form.searchfor.value == "comp"){
			str ='ss='+escape(str);
			str = "http://dir.indiamart.com/cgi/compcatsearch.mp?"+str;
			str = myReplace(str,"\\\\?\\\\&","?");
			window.location = str;
			return false;
                }
                else if(Form.searchfor.value == "product"){
			str ='ss='+escape(str);
			str = "http://catalogs.indiamart.com/cgi/catprdsearch.mp?"+str;
			str = myReplace(str,"\\\\?\\\\&","?");
			window.location = str;
			return false;
                }
                else if(Form.searchfor.value == "offer"){
			Form.search.value = str;
 			str ='search='+escape(str);
 			str = myReplace(str,"\\\\?\\\\&","?");
			Form.action = "http://trade.indiamart.com/search.mp?"+str;
			Form.submit();
			return false;
                }
		else if(Form.searchfor.value == "tenders"){
			str ='ss='+escape(str);
			str = "http://tenders.indiamart.com/search.cgi?"+str;
			str = myReplace(str,"\\\\?\\\\&","?");
			window.location = str;
			return false;
		}
		else if(Form.searchfor.value == "leads"){
			Form.search.value = str;

			var dispType = document.createElement('INPUT');
			dispType.setAttribute('name', 'disp');
			dispType.setAttribute('value', 'B');
			dispType.setAttribute('type', 'hidden');
			Form.appendChild(dispType); 
			
 			str ='search='+escape(str);
 			str = myReplace(str,"\\\\?\\\\&","?");
			Form.action = "http://trade.indiamart.com/search.mp?"+str;
			Form.submit();
			return false;
		}
	}
}

function myReplace(str, a, b) {
        var re = new RegExp(a, "g");
        var ret = str.replace(re,b);
        return ret;
}

function trim(sString)
{ 
	sString = sString.replace(/^\s+/g, '').replace(/\s+$/g, ''); 
	return sString; 
}

function openchildts(thisurl) { browserName = navigator.appName; browserVer = parseInt(navigator.appVersion);
condition = !(( (browserName.indexOf("Explorer") >=0 ) && (browserVer < 4) ) ||  ((browserName.indexOf("Netscape") >=0 ) && (browserVer < 2) ) ) ;
if (condition == true  )
CanAnimate = true;
else
CanAnimate = false;
if ( CanAnimate ) {
var windowHeight; var windowWidth; var windowTop; var windowLeft;
windowHeight=(screen.height*(80/100))*0.85; windowWidth=(screen.width*(57/100)-200);
windowTop=(screen.height*(20/100))*0.8; windowLeft=screen.width*(40.2/100);
msgWindow=window.open( '' ,'subwindow','toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,menubar=no,resizable=yes,top='+windowTop+',left='+windowLeft+',width='+windowWidth+',height='+windowHeight);
msgWindow.focus(); msgWindow.location.href = thisurl; }
else {
msgWindow=window.open( thisurl,'subwindow','toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,menubar=no,resizable=yes,width=510,height=420'); } }

function searchCaption(Form)
{
	var re = /(Enter\s+.*?Search)/i;

	if(Form.searchfor.value == "comp" && Form.ss.value.match( re ))
	{
		Form.ss.value = 'Enter Product / Company Name to Search ...';	
		return false;
	}
	else if(Form.searchfor.value == "product" && Form.ss.value.match( re ))
	{
		Form.ss.value = 'Enter Product / Company Name to Search ...';	
		return false;
	}
	else if(Form.searchfor.value == "tenders" && Form.ss.value.match( re ))
	{
		Form.ss.value = 'Enter keyword / company name to search preferred tenders ...';	
		return false;
	}
	else if(Form.searchfor.value == "offer" && Form.ss.value.match( re ))
	{
		Form.ss.value = 'Enter Product / Service Offers to Search ...';	
		return false;
	}
	else if(Form.searchfor.value == "leads" && Form.ss.value.match( re ))
	{
		Form.ss.value = 'Enter Product / Service Buy Leads to Search ...';	
		return false;
	}
}
