
function checkData (myobjname) {
	var myElement=myobjname.value;
	if (myElement.length < 3) {
		alert("Enter at least three characters for search.");
		myobjname.focus();
		return false;
	} else {
		return true;
	}
}

function checkData1 ()
{
	if (document.form2.ss.value.length < 3){
	    alert("Enter at least three characters for search.");
	    document.form2.ss.focus();
	    return false;
	}
	else{
		return true;
	}
}

function viewdesc(ref)
{
	window.open(ref,'Lookup', 'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=665,height=480' );
}

function send_url(url){

	if(window.opener.closed)    {
		msg = window.open(url);
		window.close();
	}
	else    {
		window.close();
		opener.location = url;
		opener.focus();
	}
}


function Check_Login() {

	if(document.loginform.usr_name.value == "" ) {
	alert("Kindly enter your User Name/E-mail ID.");
	document.loginform.usr_name.focus();
	return false;
	}
	else if(document.loginform.usr_name.value.length < 4) {
	alert("The User Name should be atleast 4 characters long.");
	document.loginform.usr_name.focus();
	return false;
	}
	else if(document.loginform.usr_pass.value == "" ) {
	alert("Kindly enter your Password.");
	document.loginform.usr_pass.focus();
	return false;
	}
	else if(document.loginform.usr_pass.value.length < 4) {
	alert("The Password should be atleast 4 characters long.");
	document.loginform.usr_pass.focus();
	return false;
	}
	else {
	return true;
	}

}


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;

function openchildts(thisurl){

if ( CanAnimate ){

        var windowHeight;
        var windowWidth;
        var windowTop;
        var windowLeft;
        windowHeight=(screen.height*(80/100))*0.85;
        windowWidth=screen.width*(57/100);
        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 CheckDataSearch(Form,isframe)
{


        var str='';
	
        Form.ss.value = Form.ss.value.replace(/^\s+/g, '').replace(/\s+$/g, '');
// 	Form.ss.value = Form.ss.value.replace(/\s+/g, '+');
	while(Form.ss.value.indexOf('  ')>0)
	{
		Form.ss.value = Form.ss.value.replace('  ',' ');	
	}
	Form.ss.value = Form.ss.value.replace(/[^a-zA-Z0-9+ ]/g, ' ');
	
	var temp=Form.ss.value.replace(/\s/g, '');
        if (Form.ss.value.length < 3)
        {
                alert("Enter at least three characters for search.");
                Form.ss.focus();
                return false;
        }
        else
        {
                if(Form.searchfor.value == "comp")
                {
			 //var a = Form.ss.value.replace(/\s+/g, '+');
			  var a = Form.ss.value.replace(/\+/g, ' ');
				a = a.replace(/\s+/g, '+');
			//a = Form.ss.value.replace(/\s+/g, '+');
			 str +='ss='+a;
			
                        //str += '&searchfor='+Form.searchfor.value;
                        //str += '&modid=DIR';

                        str = "http://dir.indiamart.com/cgi/compcatsearch.mp?"+str;
                        str = myReplace(str,"\\\\?\\\\&","?");
			if(isframe ==1)
			{
				parent.window.location = str;
			}
			else
			{
                        	window.location = str;
			}
                        return false;
                }
                else if(Form.searchfor.value == "product")
                {
			 var b = Form.ss.value.replace(/\+/g, ' ');
				b = b.replace(/\s+/g, '+');
                        str +='ss='+b;
                        //str += '&searchfor='+Form.searchfor.value;
                        //str +='&modid=CTL';

                        str = "http://catalogs.indiamart.com/cgi/catprdsearch.mp?"+str;
                        str = myReplace(str,"\\\\?\\\\&","?");

                        if(isframe ==1)
			{
				parent.window.location = str;
			}
			else
			{
                        	window.location = str;
			}
                        return false;
                }
                else if(Form.searchfor.value == "offer")
                {
			var c = Form.ss.value.replace(/\+/g, ' ');
				c = c.replace(/\s+/g, '+');
                        str +='search='+c;
                        //str += '&searchfor='+Form.searchfor.value;
                        //str +='&modid=ETO';

                        //str +='&search='+Form.ss.value;
                        str = "http://trade.indiamart.com/search.mp?"+str;
                        str = myReplace(str,"\\\\?\\\\&","?");

                        if(isframe ==1)
			{
				parent.window.location = str;
			}
			else
			{
                        	window.location = str;
			}
                        return false;
                }
                else if(Form.searchfor.value == "tenders")
                {
			
			var d = Form.ss.value.replace(/\+/g, ' ');
			d = d.replace(/\s+/g, '+');
			d = d.toLowerCase();
                        str +='ss='+d;
			str = "http://tenders.indiamart.com/search.cgi?"+str;
                        str = myReplace(str,"\\\\?\\\\&","?");

                        if(isframe ==1)
			{
				parent.window.location = str;
			}
			else
			{
                        	window.location = str;
			}
                        return false;
                }
        }
}




function SearchForForign(Form,isframe)
{
        var str='';
	Form.ss.value = Form.ss.value.replace(/\+/g, ' ');
        Form.ss.value = Form.ss.value.replace(/^\s+/g, '');
	Form.ss.value = Form.ss.value.replace(/\s+$/g, '');
	Form.ss.value = Form.ss.value.replace(/\s+/g, ' ');
	if (Form.ss.value.length < 3)
        {
                alert("Enter at least three characters for search.");
                Form.ss.focus();
                return false;
        }
        else
        {
		if(Form.searchfor.value == "comp")
                {
                        var str1 = Form.ss.value.replace(/\s+/g, '+');
                        str +='ss='+escape(str1);
			
			if(Form.modid.value)
			{
				str += '&modid='+Form.modid.value;
			}

                        str = "http://dir.indiamart.com/cgi/compcatsearch.mp?"+str;
			str = myReplace(str,"\\\\?\\\\&","?");
			if(isframe ==1)
			{
				parent.window.location = str;
			}
			else
			{
                        	window.location = str;
			}
                        return false;
                }
                else if(Form.searchfor.value == "product")
                {
                        str +='ss='+escape(Form.ss.value);
                        //str += '&searchfor='+Form.searchfor.value;
                        //str +='&modid=CTL';

                        str = "http://catalogs.indiamart.com/cgi/catprdsearch.mp?"+str;
                        str = myReplace(str,"\\\\?\\\\&","?");

                        if(isframe ==1)
			{
				parent.window.location = str;
			}
			else
			{
                        	window.location = str;
			}
                        return false;
                }
                else if(Form.searchfor.value == "offer")
                {
                        str +='search='+escape(Form.ss.value);
                        //str += '&searchfor='+Form.searchfor.value;
                        //str +='&modid=ETO';

                        //str +='&search='+Form.ss.value;
                        str = "http://trade.indiamart.com/search.mp?"+str;
                        str = myReplace(str,"\\\\?\\\\&","?");

                        if(isframe ==1)
			{
				parent.window.location = str;
			}
			else
			{
                        	window.location = str;
			}
                        return false;
                }
                else if(Form.searchfor.value == "tenders")
                {
                        str +='ss='+escape(Form.ss.value);
                        str += '&searchfor='+Form.searchfor.value;
                        str +='&modid=TDR';
                        str +='&cr=td';
                        str +='&sr=1';

                        str = "http://tenders.indiamart.com/tenders-search.pl?"+str;
                        str = myReplace(str,"\\\\?\\\\&","?");

                        if(isframe ==1)
			{
				parent.window.location = str;
			}
			else
			{
                        	window.location = str;
			}
                        return false;
                }
        }
}

function myReplace(str, a, b) {
        var re = new RegExp(a, "g");
        var ret = str.replace(re,b);
        return ret;
}


function resize_img(Obj, image, h_limit, w_limit)
{
	myImage = new Image();
	myImage.src = image;
	var height = myImage.height;
	var width  = myImage.width;
	if(h_limit)
	{
		h = h_limit;
	}
	else
	{
		h=100;
	}

	if(w_limit)
	{
		w = w_limit;
	}
	else
	{
		w = 100;
	}
	
	if(height > h || width > w)
	{
		if(height > width)
		{
			var temp = height/h;

			var new_width = width / temp;
			new_width = parseInt(new_width);

			height = h;
			width = new_width;
		}
		else
		{
			var temp = width/w;

			var new_height = height / temp;
			new_height = parseInt(new_height);

			height = new_height;
			width = w;
		}
	}
	Obj.height = height;
	Obj.width = width;
}
