function checkAll(field)
	{
	if (field[0].checked == true){
	for (i = 0; i < field.length; i++)
		field[i].checked = true ;
	}
	else{
		for (i = 0; i < field.length; i++)
		field[i].checked = false ;
	}
	}
	
//Pop up a new window
function popup(aUrl,width,height) 
 { var w;
   var u;
   var s = 'scrollbars=no,menubar=no,status=no,toolbar=no,left=10,top=10,width=' + width + ',height=' + height;
   u = aUrl;w = window.open(u,'',s);
 }

function antispam(name,domain) {
    	document.location = "mailto:" + name + "@" + domain;
	}
	
	
	function select_innerHTML(objeto,innerHTML){
/******
* select_innerHTML - corrige o bug do InnerHTML em selects no IE
* Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
* Vers??o: 2.1 - 04/09/2007
* Autor: Micox - N?ron Jos?C. Guimar??es - micoxjcg@yahoo.com.br
* @objeto(tipo HTMLobject): o select a ser alterado
* @innerHTML(tipo string): o novo valor do innerHTML
*******/
    objeto.innerHTML = ""
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    if(innerHTML.indexOf("<option")<0){//se n??o ?option eu converto
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span")
    selTemp.innerHTML = innerHTML
      
    
    for(var i=0;i<selTemp.childNodes.length;i++){
  var spantemp = selTemp.childNodes[i];
  
        if(spantemp.tagName){     
            opt = document.createElement("OPTION")
    
   if(document.all){ //IE
    objeto.add(opt)
   }else{
    objeto.appendChild(opt)
   }       
    
   //getting attributes
   for(var j=0; j<spantemp.attributes.length ; j++){
    var attrName = spantemp.attributes[j].nodeName;
    var attrVal = spantemp.attributes[j].nodeValue;
    if(attrVal){
     try{
      opt.setAttribute(attrName,attrVal);
      opt.setAttributeNode(spantemp.attributes[j].cloneNode(true));
     }catch(e){}
    }
   }
   //getting styles
   if(spantemp.style){
    for(var y in spantemp.style){
     try{opt.style[y] = spantemp.style[y];}catch(e){}
    }
   }
   //value and text
   opt.value = spantemp.getAttribute("value")
   opt.text = spantemp.innerHTML
   //IE
   opt.selected = spantemp.getAttribute('selected');
   opt.className = spantemp.className;
  } 
 }    
 document.body.removeChild(selTemp)
 selTemp = null
}
	
	
function validateenquiry(form){
checkName = trim(form.txtName.value)
checkEmail = trim(form.txtEmail.value)
aliaspos = checkEmail.indexOf("@")
dotpos = checkEmail.lastIndexOf(".")
checkPhone = trim(form.txtPhone.value)
checkCAPTCHA = trim(form.txtCAPTCHA.value)

if (checkName.length < 1){
alert("Please enter your name")
return false
}
else if (checkEmail.length < 1){
alert("Please enter your email")
return false
}
else if (aliaspos == -1 || dotpos == -1)
{ alert ("Not a valid email.")
return false
}
else if (checkPhone.length < 1){
alert("Please enter your phone")
return false
}
else if (checkCAPTCHA.length < 1){
alert("Write the characters in the image above")
return false
}

return true
}

function validatecontact(form){
checkSubject = trim(form.txtSubject.value)
checkMessage = trim(form.txtMessage.value)
checkName = trim(form.txtName.value)
checkEmail = trim(form.txtEmail.value)
aliaspos = checkEmail.indexOf("@")
dotpos = checkEmail.lastIndexOf(".")
checkPhone = trim(form.txtPhone.value)
checkCAPTCHA = trim(form.txtCAPTCHA.value)

if (checkSubject.length < 1){
alert("Please enter your subject")
return false
}
else if (checkMessage.length < 1){
alert("Please enter your message")
return false
}
else if (checkName.length < 1){
alert("Please enter your name")
return false
}
else if (checkEmail.length < 1){
alert("Please enter your email")
return false
}
else if (aliaspos == -1 || dotpos == -1)
{ alert ("Not a valid email.")
return false
}
else if (checkPhone.length < 1){
alert("Please enter your phone")
return false
}
else if (checkCAPTCHA.length < 1){
alert("Write the characters in the image above")
return false
}

return true
}

function validatecontacttt(form){
checkCompanyName = trim(form.txtCompanyName.value)
checkMessage = trim(form.txtMessage.value)
checkName = trim(form.txtName.value)
checkEmail = trim(form.txtEmail.value)
aliaspos = checkEmail.indexOf("@")
dotpos = checkEmail.lastIndexOf(".")
checkPhone = trim(form.txtPhone.value)
checkCAPTCHA = trim(form.txtCAPTCHA.value)

if (checkCompanyName.length < 1){
alert("Please enter your company name")
return false
}
else if (checkName.length < 1){
alert("Please enter your name")
return false
}
else if (checkPhone.length < 1){
alert("Please enter your phone")
return false
}
else if (checkEmail.length < 1){
alert("Please enter your email")
return false
}
else if (aliaspos == -1 || dotpos == -1)
{ alert ("Not a valid email.")
return false
}
else if (checkMessage.length < 1){
alert("Please enter your message")
return false
}
else if (checkCAPTCHA.length < 1){
alert("Write the characters in the image above")
return false
}

return true
}

function validateprofile(form)
{
checkSalutation = trim(radioVal(form.radSalutation))
checkName = trim(form.txtName.value)
checkStreet = trim(form.txtStreet.value)
checkCity = trim(form.txtCity.value)
checkState = trim(form.txtState.value)
checkZip = trim(form.txtZip.value)
checkCountry = form.cbbCountry.selectedIndex
checkPhone = trim(form.txtPhone.value)
checkFax = trim(form.txtFax.value)
checkEmail = trim(form.txtEmail.value)
aliaspos = checkEmail.indexOf("@")
dotpos = checkEmail.lastIndexOf(".")
checkBizType = form.cbbBizType.selectedIndex
checkType = trim(radioVal(form.radType))

if (checkSalutation.length < 1){
alert("Please select your salutation")
return false
}
else if (checkName.length < 1){
alert("Please enter your name")
return false
}
else if (checkStreet.length < 1){
alert("Please enter your street")
return false
}
else if (checkCity.length < 1){
alert("Please enter your city")
return false
}
else if (checkState.length < 1){
alert("Please enter your state")
return false
}
else if (checkZip.length < 1){
alert("Please enter your zip")
return false
}
else if (checkCountry == 0){
alert("Please select your country")
return false
}
else if (checkPhone.length < 1){
alert("Please enter your phone")
return false
}
else if (checkFax.length < 1){
alert("Please enter your fax")
return false
}
else if (checkEmail.length < 1){
alert("Please enter your email")
return false
}
else if (aliaspos == -1 || dotpos == -1)
{ alert ("Not a valid email")
return false
}
else if (checkBizType == 0){
alert("Please select your business type")
return false
} 
else if (checkType.length < 1){
alert("Are you a buyer or seller? Please select an option.")
return false
}

return true
}

function validateproduct(form)
{
checkProductName = trim(form.txtProductName.value)
checkMainCategory = form.cbbMainCategory.selectedIndex
checkSubCategory = form.cbbSubCategory.selectedIndex

if (checkProductName.length < 1){
alert("Please enter your product name")
return false
}
else if (checkMainCategory == 0){
alert("Please select main category")
return false
}
else if (form.cbbSubCategory[checkSubCategory].value == ''){
alert("Please select sub category")
return false
}

return true
}

function validatesignup(form)
{
checkLoginId = trim(form.txtLoginId.value)
checkPassword = trim(form.txtPassword.value)
checkPassword2 = trim(form.txtPassword2.value)
checkSalutation = trim(radioVal(form.radSalutation))
checkName = trim(form.txtName.value)
checkCompanyName = trim(form.txtCompanyName.value)
checkStreet = trim(form.txtStreet.value)
checkCity = trim(form.txtCity.value)
checkState = trim(form.txtState.value)
checkZip = trim(form.txtZip.value)
checkCountry = form.cbbCountry.selectedIndex
checkPhone = trim(form.txtPhone.value)
checkFax = trim(form.txtFax.value)
checkEmail = trim(form.txtEmail.value)
aliaspos = checkEmail.indexOf("@")
dotpos = checkEmail.lastIndexOf(".")
checkBizType = form.cbbBizType.selectedIndex
checkType = trim(radioVal(form.radType))
checkCAPTCHA = trim(form.txtCAPTCHA.value)

if (checkLoginId.length < 1){
alert("Please enter your login id")
return false
}
else if (checkPassword.length < 1){
alert("Please enter your password")
return false
}
else if (checkPassword2.length < 1){
alert("Please re enter your password")
return false
}
else if (checkPassword != checkPassword2){
alert("Your new password don't match")
return false
}
else if (checkSalutation.length < 1){
alert("Please select your salutation")
return false
}
else if (checkName.length < 1){
alert("Please enter your name")
return false
}
else if (checkStreet.length < 1){
alert("Please enter your street")
return false
}
else if (checkCity.length < 1){
alert("Please enter your city")
return false
}
else if (checkState.length < 1){
alert("Please enter your state")
return false
}
else if (checkZip.length < 1){
alert("Please enter your zip")
return false
}
else if (checkCountry == 0){
alert("Please select your country")
return false
}
else if (checkPhone.length < 1){
alert("Please enter your phone")
return false
}
else if (checkFax.length < 1){
alert("Please enter your fax")
return false
}
else if (checkEmail.length < 1){
alert("Please enter your email")
return false
}
else if (aliaspos == -1 || dotpos == -1)
{ alert ("Not a valid email")
return false
}
else if (checkBizType == 0){
alert("Please select your business type")
return false
} 
else if (checkType.length < 1){
alert("Are you a buyer or seller? Please select an option.")
return false
}
else if (checkCAPTCHA.length < 1){
alert("Write the characters in the image above")
return false
}

return true
}

function CreateBookmarkLink() {

 title = "Tradetycoon"; 
 url = "http://tradetycoon.com";

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
 }



function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
	
//howManyChecked('myform','cb_industry',6,1,'Industry');
function howManyChecked(whichForm,whichCheckBoxArray,myMax,myMin,whichQuestion)
/*
  This function takes 5 paramaters:
  whichForm -- the NAME of the form to be validated, a string
  whichCheckBoxArray -- the NAME of the checkbox to be checked, a string
  myMax -- the most you want the user to be able to check, an integer
  myMin -- the least you want the user to be able to check, an integer
  whichQuestion -- a short description of the question, a string
  
  example use:
  howManyChecked('myform','cb_industry',6,1,'Industry');
*/
{
	var _countChecked = 0;
	var err = 0;
	/* iterate through all the elements in the checkbox array */
	for(i=1;i<document[whichForm][whichCheckBoxArray].length;i++)
	{
		/* and check to see if each is checked */
		if(document[whichForm][whichCheckBoxArray][i].checked==true)
			/* if it is, increment a counter */
			{ _countChecked++; }
	}
	/* is the count too high? */
	if(_countChecked > myMax)
		{ alert('Limit '+myMax+' checks for '+whichQuestion);
			err = 1;}
	/* of is the count too low */
	else if(_countChecked < myMin)
		{ alert('You must select at least '+myMin+' entry(s) for '+whichQuestion);
			err = 1;}
	if (err == 1) { return false; }
}

function sync(whichForm,whichCheckBoxArray,whichHiddenArray)
{

	for(i=0;i<document[whichForm][whichHiddenArray].length;i++)
	{
			document[whichForm][whichHiddenArray][i].disabled = true;

	}

	/* iterate through all the elements in the checkbox array */
	for(i=1;i<document[whichForm][whichCheckBoxArray].length;i++)
	{
		/* and check to see if each is checked */
		if(document[whichForm][whichCheckBoxArray][i].checked==true)
			{ 
			document[whichForm][whichHiddenArray][i-1].disabled = false;
			}

	}

}

function validatesearch(form) {
			if (trim(form.txtSearch.value) == "") {
				return false
			} 
			if (valButton(form.t) == "c"){
			form.action = "/sr_companies.asp";
			}else if (valButton(form.t) == "p"){
			form.action = "/sr_products.asp";
			}
			return true
		};
		
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

function showHide(objid, imgid) {
    if (document.getElementById(objid).style.display == "block") {
        document.getElementById(objid).style.display = "none";
        document.getElementById(imgid).src = '/images/common/close.gif';
    } else {
        document.getElementById(objid).style.display = "block";
       document.getElementById(imgid).src = '/images/common/open.gif';
    }
}

function showReply(objid) {
    if (document.getElementById(objid).style.display == "block") {
        document.getElementById(objid).style.display = "none";
    } else {
        document.getElementById(objid).style.display = "block";
		document.location.href='#reply';
    }
}

function validatepassword(form){
checkOldPassword = trim(form.txtOldPassword.value)
checkNewPassword = trim(form.txtNewPassword.value)
checkNewPassword2 = trim(form.txtNewPassword2.value)

if (checkOldPassword.length < 1){
alert("Please enter your old password")
return false
}
else if (checkNewPassword.length < 1){
alert("Please enter your new password")
return false
}
else if (checkNewPassword2.length < 1){
alert("Please re enter your new password")
return false
}
else if (checkNewPassword != checkNewPassword2){
alert("Your new password don't match")
return false
}

return true
}

function validatemessage(form){
checkMessage = trim(form.txtMessage.value)

if (checkMessage.length < 1){
alert("Please enter your message")
return false
}

return true
}

function validatelogin(form){
checkLoginId = trim(form.txtLoginId.value)
checkPassword = trim(form.txtPassword.value)

if (checkLoginId.length < 1){
alert("Please enter your login id")
return false
}
else if (checkPassword.length < 1){
alert("Please enter your password")
return false
}

return true
}

function validateforgotpassword(form){
checkLoginId = trim(form.txtLoginId.value)
checkEmail = trim(form.txtEmail.value)
aliaspos = checkEmail.indexOf("@")
dotpos = checkEmail.lastIndexOf(".")

if (checkLoginId.length < 1 && checkEmail.length < 1){
alert("Please enter your login id or your email")
return false
}
else if (checkEmail.length > 0 && (aliaspos == -1 || dotpos == -1))
{ alert ("Not a valid email")
return false
}

return true
}


function radioVal(btn) {
var cnt = -1;
for (var i=btn.length-1; i > -1; i--) {
   if (btn[i].checked) {cnt = i; i = -1;}
   }
if (cnt > -1) return btn[cnt].value;
else return "";
}

  
  
function deleteMessage(whichForm,whichCheckBoxArray)
{
	var _countChecked = 0;
	var err = 0;
	var querystring = '';

	if(document[whichForm][whichCheckBoxArray].value==undefined){
		for(i=0;i<document[whichForm][whichCheckBoxArray].length;i++)
		{
			if(document[whichForm][whichCheckBoxArray][i].checked==true)
				{ _countChecked++; 
				if (querystring == ''){ querystring = '?MsgId=' + document[whichForm][whichCheckBoxArray][i].value; } else { querystring = querystring + '&MsgId=' + document[whichForm][whichCheckBoxArray][i].value; }
				}
		}
	}
	else {
		if(document[whichForm][whichCheckBoxArray].checked==true)
				{ _countChecked++; 
				if (querystring == ''){ querystring = '?MsgId=' + document[whichForm][whichCheckBoxArray].value; } else { querystring = querystring + '&MsgId=' + document[whichForm][whichCheckBoxArray].value; }
				}
	}
	
	if (_countChecked == 0) {
		alert('You must select at least 1 Message');
	}
	else {
		window.open('cus-message-delete.asp'+querystring,'','resizable=no,width=400,height=200');
	}
}

function unsubscribe(whichForm,whichCheckBoxArray)
{
	var _countChecked = 0;
	var err = 0;
	var querystring = '';

	if(document[whichForm][whichCheckBoxArray].value==undefined){
		for(i=0;i<document[whichForm][whichCheckBoxArray].length;i++)
		{
			if(document[whichForm][whichCheckBoxArray][i].checked==true)
				{ _countChecked++; 
				if (querystring == ''){ querystring = '?CatId=' + document[whichForm][whichCheckBoxArray][i].value; } else { querystring = querystring + '&CatId=' + document[whichForm][whichCheckBoxArray][i].value; }
				}
		}
	}
	else {
		if(document[whichForm][whichCheckBoxArray].checked==true)
				{ _countChecked++; 
				if (querystring == ''){ querystring = '?CatId=' + document[whichForm][whichCheckBoxArray].value; } else { querystring = querystring + '&CatId=' + document[whichForm][whichCheckBoxArray].value; }
				}
	}
	
	
	if (_countChecked == 0) {
		alert('You must select at least 1 Category');
	}
	else {
		window.open('cus-unsubscribe.asp'+querystring,'','resizable=no,width=400,height=200');
	}
}
