function popup_job(file){
newwin=window.open(file,'Job_Print','status=0,toolbar=0,width=955,height=500');
if (window.focus) {newwin.focus()}


return false;
}

function popup_prot(file){
newwin=window.open(file,'Protection','status=0,toolbar=0,width=955,height=350');
if (window.focus) {newwin.focus()}


return false;
}


function show_p(id,idc){
	if($(id).style.display=='none'){
	$('overview').style.display='none';
	$('benefits').style.display='none';
	$('s_equip').style.display='none';
	$('o_equip').style.display='none';
	$('w_tools').style.display='none';
	$('over').className='';
	$('bene').className='';
	$('sequ').className='';
	$('oequ').className='';
	$('wtoo').className='';
	
	$(id).style.display='block';
	$(idc).className='active';
	}
	
	

}

function is_empty (str) {
	return ((str.length==0) ? true : false);
}

function is_number (n) {
	var digitExp = /^[0-9]*$/; 
	
	if(digitExp.test(n)) return true;

	return false;
}

function is_letter (n) {
	var alphaExp = /^[a-zA-Z]*$/; 
	
	if(alphaExp.test(n)) return true;

	return false;
}

function check_digit (id) {
	var n_val = '';
	var ob = jQuery('#'+id).val();	
	for(var i=0;i<ob.length;i++) {		
		if(is_number(ob.substr(i, 1))) n_val += ob.substr(i, 1);
	}
	jQuery('#'+id).val(n_val);
}

function check_letter (id) {
	var n_val = '';
	var ob = jQuery('#'+id).val();	
	for(var i=0;i<ob.length;i++) {		
		if(is_letter(ob.substr(i, 1))) n_val += ob.substr(i, 1);
	}
	jQuery('#'+id).val(n_val);
}

function check_alphanum (id) {
	var n_val = '';
	var ob = jQuery('#'+id).val();	
	for(var i=0;i<ob.length;i++) {		
		if(is_letter(ob.substr(i, 1)) || is_digit(ob.substr(i, 1))) n_val += ob.substr(i, 1);
	}
	jQuery('#'+id).val(n_val);
}

function is_ascii(event) {
	var t = event.which?event.which:event.keyCode;
	if(t >= 48 && t <= 57 || t >= 65 && t <= 89 || t >= 97 && t <= 121 || t==32) {
		return true;
	} else {
		return false;
	}
}

function is_email (emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {
		//alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}

	var user=matchArray[1];
	var domain=matchArray[2];

	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			//alert("Ths username contains invalid characters.");
			return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			//alert("Ths domain name contains invalid characters.");
			return false;
	   }
	}

	if (user.match(userPat)==null) {
	//	alert("The username doesn't seem to be valid.");
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				//alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			//alert("The domain name does not seem to be valid.");
			return false;
	   }
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		//alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}

	if (len<2) {
		//alert("This address is missing a hostname!");
		return false;
	}

	return true;
}

/* preloading images */
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//******************************************************************************

	var qs = new Querystring();
	var unit = qs.get("unit","");

	var jsunit = unit;

// this function is needed to work around
// a bug in IE related to element attributes
function hasClass(obj) {
    	var result = false;
	    if (obj.getAttributeNode("class") != null) {
        	result = obj.getAttributeNode("class").value;
     	}
	    return result;
	}



function stripeTables(id,evenColor) {
		var even = false;
		var table = document.getElementById(id);
		// obtain a reference to the desired table
				// if no such table exists, abort
		if (!table) { return; }
		// by definition, tables can have more than one tbody
		// element, so we'll have to get the list of child
		// &lt;tbody&gt;s
		var tbodies = table.getElementsByTagName("tbody");
		// and iterate through them...
		for (var h = 0; h < tbodies.length; h++) {
			// find all the &lt;tr&gt; elements...
			var trs = tbodies[h].getElementsByTagName("tr");
			// ... and iterate through them
			for (var i = 0; i < trs.length; i++) {
				// avoid rows that have a class attribute
				// or backgroundColor style
				if (!hasClass(trs[i]) && !trs[i].style.backgroundColor) {
					// get all the cells in this row...
					var tds = trs[i].getElementsByTagName("td");

					// and iterate through them...
					for (var j = 0; j < tds.length; j++) {
						var mytd = tds[j];
						// avoid cells that have a class attribute
						// or backgroundColor style
						if (!hasClass(mytd) && !mytd.style.backgroundColor) {
							if (i % 4 == 0) {
								mytd.style.backgroundColor = evenColor;
							}
						}
					}
				}
				even =  ! even;
			}
		}

	}

	function Querystring(qs) {
		this.params = {};
		this.get=Querystring_get;
		if (qs == null) {
			qs=location.search.substring(1,location.search.length);
		}
		if (qs.length == 0) {
			return;
		}
	// Turn <plus> back to <space>
	// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
		qs = qs.replace(/\+/g, ' ');
		var args = qs.split('&'); // parse out name/value pairs separated via &

	// split out each name=value pair
		for (var i=0;i<args.length;i++) {
			var pair = args[i].split('=');
			var name = unescape(pair[0]);

			var value = (pair.length==2)? unescape(pair[1]): name;

			this.params[name] = value;
		}
	}
	function Querystring_get(key, default_) {
		var value=this.params[key];
		return (value!=null) ? value : default_;
	}

	function leftnavOn(el) {
    if (el.parentElement) {
      el.parentElement.parentElement.style.backgroundColor="#eeeeee";
    }
	}
	function topnavOn(el,wedge) {
		el.parentElement.style.backgroundColor="#333333";
		document.images[wedge].src = "images/global/nav_wedge_on.gif";
	}

	function topnavOff(el,wedge) {
		el.parentElement.style.backgroundColor="#4D4D4D";
		document.images[wedge].src = "images/global/nav_wedge.gif";
	}

	function openWin(url, w, h) {
		newwindow = window.open(url, "_new", "width=" + w + ",height=" + h + ",toolbar=yes,scrollbars=yes,resizable=yes");
	}
	function printWin(url, w, h) {
		url = url+jsunit;
		printwin = open(url,"_new", "width=" + w + ",height=" + h + ",toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
		printwin.focus();
		printwin.print();
	}
	function light(el) {
		el.parentElement.parentElement.parentElement.bgColor = "#ffcc00";
	}

	function unlight(el){
		el.parentElement.parentElement.parentElement.bgColor = "#666666";
	}
	function leftnavOff(el) {
    if (el.parentElement) {
      el.parentElement.parentElement.style.backgroundColor="#dddddd";
    }
	}
	function getElementsByClass() {
		var classElements = new Array();
		node = document;
		tag = 'td';
		var els = node.getElementsByTagName(tag);
		var elsLen = els.length;
		var pattern = new RegExp('showhide');

		for (i = 0, j = 0; i < elsLen; i++) {

			if (els[i].className.indexOf('showhide') > -1) {
				classElements[j] = els[i];
				j++;
			}
		}
		return classElements;
	}
	function showcol(column,linkID){
		cols = getElementsByClass();

		for (i=0; i < cols.length; i++){
			theId = cols[i].id;
			if (theId.indexOf("column_"+column) > -1){
				show(theId);
			}
		}
		otherLinkID="none";
		if (linkID=="metricLink"){
			otherLinkID="usLink";
			jsunit = "metric";
		}
		if (linkID=="usLink") {
			otherLinkID="metricLink";
			jsunit = "us";
		}
		link1=document.getElementById(linkID);
		link2=document.getElementById(otherLinkID);
		toggleLink(link1,link2);
	}
	function hidecol(column){
		cols = getElementsByClass();

		for (i=0; i < cols.length; i++){
			theId = cols[i].id;
			if (theId.indexOf("column_"+column) > -1){
				hide(theId);
			}
		}
	}

//begin Units US/Metric functionality
function flipshow(column,linkID){
		leng = 50;
		if (column==0){
			column2=1;
			column3=2;

			otherColumn=3;
			otherColumn2=4;
			otherColumn3=5;
		}
		else {
			column=3;
			column2=4;
			column3=5;

			otherColumn=0;
			otherColumn2=1;
			otherColumn3=2;
		}
		for (i = 1; i < leng; i++) {
			theId = "column_" + column + "_" + i;
			theId2 = "column_" + column2 + "_" + i;
			theId3 = "column_" + column3 + "_" + i;
			theOtherId = "column_" + otherColumn + "_" + i;
			theOtherId2 = "column_" + otherColumn2 + "_" + i;
			theOtherId3 = "column_" + otherColumn3 + "_" + i;
			show(theId);
			show(theId2);
			show(theId3);
			hide(theOtherId);
			hide(theOtherId2);
			hide(theOtherId3);
		}
		otherLinkID="none";
		if (linkID=="metricLink"){
			otherLinkID="usLink";
		}
		if (linkID=="usLink") {
			otherLinkID="metricLink";
		}
		link1=document.getElementById(linkID);
		link2=document.getElementById(otherLinkID);
		toggleLink(link1,link2);
		}

function hide(theId){
		if (document.getElementById(theId)!=null){
			document.getElementById(theId).style.display = 'none';
			}
		}
function show(theId){
		if (document.getElementById(theId)!=null){
			document.getElementById(theId).style.display = '';
			}
		}
	function cancelLink () {
  		return false;
		}
	function disableLink (link) {
  		if (link.onclick)
		    link.oldOnClick = link.onclick;
		  	link.onclick = cancelLink;
  		if (link.style)
    		link.style.cursor = "default";
			}
	function enableLink (link) {
  			link.onclick = link.oldOnClick ? link.oldOnClick : null;
			if(link.style)
    		link.style.cursor = document.all ? "hand" : "pointer";
			}
			//end  Units US/Metric functionality

	function toggleLink (link1,link2) {
		    enableLink(link2);
			link2.disabled = false;
			link1.disabled = true;
		}
	function performSubmit(formselect){
		url = formselect.options[formselect.selectedIndex].value;
		if (url != "X"){
			window.location = url+jsunit;
		}
	}
	function callurl(url){

		window.location = url+jsunit;
	}
	function launchConfigurator(linkType,productID,regionid,famid,prodname,familyheader)
	{
	  var configWin = null;
	  var serverurl = "http://buildandquote.cat.com/SEUILibrary/controller/CAT:Enter?";

  		if (!configWin || configWin.closed)
  		{
		   configWin = window.open(serverurl+ "prdname=" + prodname  + "&amp;prodid=" + productID + "&amp;linkType=" + linkType + "&amp;subfamilyheader=" + familyheader + "&amp;rgnid=" + regionid + "&amp;familyid=" + famid , "configurator", "menubar=0,toolbar=0,location=0,directories=0,status=1,resizable=1,scrollbars=0,width=770,height=580");
		   configWin.focus();
		}
		else
		{
		   configWin.focus();
		}
 	}
 	function launchCompeteCompare(prodid,mkgorg,uom,lang_id)
	{
	  var comsoccWin = null;
	  var serverurl = "http://stage-wizportal.catmms.com/wizportal/comsocc/jsp/comparableProducts.jsp?";
  	  var comsoccUrl = "product_id="+prodid+"&marketing_org="+mkgorg+"&unit_of_measure="+uom+"&lang_id="+lang_id;

  		if (!comsoccWin || comsoccWin.closed)
  		{
		   comsoccWin = window.open(serverurl+escape(comsoccUrl), "comsocc", "menubar=0,toolbar=0,location=0,directories=0,status=1,resizable=1,scrollbars=1,width=770,height=580");
		   comsoccWin.focus();
		}
		else
		{
		   comsoccWin.focus();
		}
 	}

function showContract(id)
{
    var content = document.getElementById("oferta_"+id+"").innerHTML;
    document.getElementById("ofertaBMContent").innerHTML = content;
}
