//parameter info
// chkName = the name of the chekboxes list without 1,2,3,... numbers
// frmName = html form name 
// chkTotal = no of checkboxes to look for
function select_all( chkName , frmName , chkTotal )
{
	var frm=document.forms[frmName];
	for(var i=0;i<frm.elements.length;i++)
	{
		var e =frm.elements[i];
		if ((e.name != 'check_all') && (e.type=='checkbox'))
		{
			e.checked =frm.check_all.checked;
		}
	}
}

function checkAll(chkName,frmName,chkTotal )
{
	var frm = document.forms[frmName];
	var i = 0;
	for (i=1 ; i<=frm.elements.length; i++)
	{
		var o = frm.elements[chkName + i.toString()];
		if (o) o.checked = true;
	}
	return false;
}

function clearAll( chkName , frmName , chkTotal )
{
	var frm = document.forms[frmName];
	var i = 0;
	for (i=1 ; i<=frm.elements.length; i++)
	{
		var o = frm.elements[chkName + i.toString()];
		if (o) o.checked = false;
	}
	return false;
}

//additional err_msg + same parameters list as the above functions checkAll and clearAll 
//err_msg will be displayed if not checkbox is not selected
function is_checked(chkName , frmName , chkTotal, err_msg)
{
	var frm = document.forms[frmName];
	var i = 0;
	for (i=1 ; i<=chkTotal ; i++)
	{
		var o = frm.elements[chkName + i.toString()];
		if(o && o.checked)
			return true;
	}
	alert(err_msg); 
	return false;
}

function get_cookie(Name) 
{
	var Name = Name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(Name) == 0) return unescape(c.substring(Name.length,c.length));
	}
	return "";
}

function checkByteLength(str,minlen,maxlen) {
	if (str == null) return false;
	var l = str.length;
	var blen = 0;
	for(i=0; i<l; i++) {
		if ((str.charCodeAt(i) & 0xff00) != 0) {
			blen ++;
		}
		blen ++;
	}
	if (blen > maxlen || blen < minlen) {
		
		return false;
	}
	return true;
}

function validateNotEmpty(obj) {
    var str = obj.value;
	if(str!=null && str.length>0){
		return 0;
	}
	return 1;
}

function isEmptyField(aTextField) {
   if ((aTextField.value==null)||(aTextField.value.replace(/(^\s*)|(\s*$)/g, "").length==0)) {
      return true;
   } else { 
      return false; 
   }
}

function validateEmail(obj){
	var str = obj.value;
	var patn = /^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[a-zA-Z0-9\-]+([\.][a-zA-Z0-9\-]+)+$/;
	if(patn.test(str)){
    	return 0;
	}else{
	    return 1; //incorrect format
	}
}
function isNumber(str) {
	var patn = new RegExp("^\\d{1,15}$"); 
	if (patn.test(str)) {
		return true;
	} else {
		return false; 	
	}
}

function checkchi(myint) {
	var checkStr = myint;
	var allValid = true;
	var len=checkStr.length;
	for (i = 0;  i <len ;  i++)
	{
		ch = checkStr.charCodeAt(i);			
		if (ch > 127 && !isOkChar(ch))
		{      
			allValid = false;
			break;
		}
	}
	if (!allValid)
	{
		return (false);
	}
	return (true);
}

function isOkChar(ch){
	var checkOk = new Array();
	checkOk[0] = "12288";
	checkOk[1] = "8364";
	for (j = 0;  j < checkOk.length;  j++)
   	if (ch == checkOk[j]){
       return true;
    }
    return false;
}	

function validateSelectValue(obj){
	var str = obj.value;		
	if(str.trim().length >0) return 0;
		return 1; 	
}

function open_window(url, width, height)
{
	var sw = window.open(url,"subWnd","Toolbar=1,menubar=0,scrollbars=1,resizable=1,width="+width+",height="+height+",top=100,left=200");
	if (!sw)
	{
		alert("Popup Blocker Detected!\n\nPlease disable your popup blocker software or allow popups on this page.");
	}
	else
	{
		sw.focus();
	}
	return false;
}

function open_window_full(url, width, height)
{
	var sw = window.open(url,"subWnd","Toolbar=0,menubar=0,scrollbars=0,resizable=1,width="+width+",height="+height+",top=0,left=0");
	if (!sw)
	{
		alert("Popup Blocker Detected!\n\nPlease disable your popup blocker software or allow popups on this page.");
	}
	else
	{
		sw.focus();
	}
	return false;
}

//Dont change window name 'subWnd', its being used on some other pages
function open_window_scroll(url, width, height)
{
	var sw=window.open(url,"subWnd","Toolbar=1,menubar=0,scrollbars=1,resizable=1,width="+width+",height="+height+",top=75,left=150");
	if (!sw)
	{
		alert("Popup Blocker Detected!\n\nPlease disable your popup blocker software or allow popups on this page.");
	}
	else
	{
		sw.focus();
	}
	return false;
}

function TextArea_Keypress( txtName , spnName )
{
	if (document.getElementById(txtName).value.length >= parseInt(document.getElementById(txtName).attributes['MaxChars'].value))
		return false;
}

function TextArea_Keyup( txtName , spnName )
{
	if (document.getElementById(txtName).value.length >= parseInt(document.getElementById(txtName).attributes['MaxChars'].value))
	{
		document.getElementById(txtName).value = document.getElementById(txtName).value.substr(0, parseInt(document.getElementById(txtName).attributes['MaxChars'].value)-1);
	}
	//document.getElementById(spnName).innerHTML = (parseInt(document.getElementById(txtName).attributes['MaxChars'].value)-parseInt(document.getElementById(txtName).value.length));
	document.getElementById(spnName).innerHTML = (parseInt(document.getElementById(txtName).value.length));
}

function trim(str)
{
	str = str.replace(/^\s*|\s*$/g,"");
	return str;
}

function loadwin(url)
{
	var left, top;
	var width = screen.width;
	// Resize the screen depending on the users display
	if(screen.width >= 1280 && screen.height >= 1024)
	{
		wdh = 850;
		hgt = 750;
	}
	else if(screen.width > 1024 && screen.height > 768)
	{
		wdh = 850;
		hgt = 700;
	}
	else if(screen.width >= 800 && screen.height >= 600)
	{
		wdh = 850;
		hgt = 640;
	}
	// Open the window in the middle of the screen
	left = (screen.availWidth - wdh) / 2
	top = (screen.availHeight - hgt) / 2 - 10;
	success = open(url, '', 'width=' + wdh + ',height=' + hgt + ',left=' + left + ',top=' + top + ',scrollbars=yes,resizable=yes,status=no');
}

function set_login_required_cookie(value)
{
	var exp = new Date( );
	var expiry = exp.getTime( ) + (60 * 60 * 1000);
	exp.setTime(expiry);
	document.cookie = "c_login_required="+ value +"; expires=" + exp.toGMTString() + ";path=/";
}

function get_validate_keyword(str1, str2, str3, charlimit)
{
var newword1="", newword2="", newword3="";

	if(str1!="")
	{
		cstr = str1.split(",");			
		for(i=0; i<cstr.length; i++)
		{ 	
			newword1 = cstr[i];			
			if(newword1.length > charlimit)
			{				
				newword1 =  newword1 + "~" + "1";				
				return newword1;
			}						
		}
	}
		
	if(str2!="")
	{		
		cstr = str2.split(",");		
		for(i=0; i<cstr.length; i++)
		{	
			newword2 = cstr[i];		
			if(newword2.length > charlimit)
			{
				newword2 =  newword2 + "~" + "2";	
				return newword2;
			} 		
		}
	}			
	
	if(str3!="")
	{		
		cstr2 = str3.split(",");		
		for(i=0; i<cstr2.length; i++)
		{	
			newword3 = cstr2[i];						
			if(newword3.length > charlimit)
			{						
				newword3 =  newword3 + "~" + "3";	
				return newword3;
			} 		
		}
	}
	
	newword2 = "true~0";
	return newword2;		
}
function menuclick(submenu,imgbar) {
	if (document.getElementById(submenu).className=="close"){
		document.getElementById(submenu).className ="exp";
		document.getElementById(imgbar).src="images/decrease.gif";
	}else{
		document.getElementById(submenu).className="close";
		document.getElementById(imgbar).src="images/adding.gif";
	}
}
function highlight_table(element, color)
{
	//document.getElementById(element).bgColor = color;
	document.getElementById(element).style.backgroundColor = color;
}


function setImgSizeWH(theURL,sImage,imgW,imgH){
var imgObj;
imgObj = new Image();
imgObj.src = theURL;
if ((imgObj.width != 0) && (imgObj.height != 0)) {
	
	if(imgObj.width>imgW || imgObj.height>imgH){
		
		var iHeight = imgObj.height*imgW/imgObj.width;
		
		if(iHeight<=imgH){
			sImage.width=imgW;
			sImage.height=iHeight;
		}else{
		var iWidth=imgObj.width*imgH/imgObj.height;
		sImage.width=iWidth;
		sImage.height=imgH;
		}
	}else{
	sImage.width=imgObj.width;
	sImage.height=imgObj.height;
	}

}else{
sImage.width = imgW;
sImage.height= imgH;
}
}

function changeSearchType(sType,obj){
	var typeSel = document.getElementById('IndexAreaOptionIdx');
	for(i=0;i<4;i++){
		typeSel[i].selected=false;
	}
	var oLi=obj.parentNode.parentNode.getElementsByTagName('li');
	for(i=0;i<oLi.length;i++){
		oLi[i].parentNode.className="";	
	}
	obj.parentNode.className="current";
	switch(sType){
		case("product"):{
			typeSel[0].selected=true;
			break;
			}
		case("buy"):{
			typeSel[1].selected=true;
			break;
			}
		case("sell"):{
			typeSel[2].selected=true;
			break;
			}
		case("company"):{
			typeSel[3].selected=true;
			break;
			}
		}
}

function addToCart(Id,type)
{
  
}

