﻿
//Find Object
function MM_findObj(n, d) { 
  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;
}

//This function is to show hide layers
function MM_showHideLayers() { 
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  	if ((obj=MM_findObj(args[i]))!=null) {
		v=args[i+2];
    	if (obj.style) { 
			obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
		}
    obj.visibility=v; 
	}
}

function MM_swapImgRestore() { 
  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() { 
  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_swapImage() { 
  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];
	}
}

function changeImage(){
	image1.src="/images/bullet_menuMouseOver.gif";
	//document.getElementById(span1).className = tax;
}

function changeClassName(id,num)
{
	//id.className="tax_ovr";
	document.getElementById("img"+num).src="/images/bullet_menuMouseOver.gif";
	obj = document.getElementById("td_"+num);
	obj.className = "tax_ovr";

}

function restoreClassName(id,num)
{
	//id.className="tax";
	document.getElementById("img"+num).src="/images/pink_bullet.gif";
	obj = document.getElementById("td_"+num);
	obj.className = "tax";

}

function changeImage(rNum,cNum)
{
	document.getElementById("img"+rNum+cNum).src="/images/menu_arrow_bullet.gif";
}

function restoreImage(rNum,cNum)
{
	document.getElementById("img"+rNum+cNum).src="/images/dropdownBullet.gif";
}

function ShowTopic(id,httphost)
{
	top.window.location.href="http://" + httphost+ "/" + strBUName +  "/TopicCategory.aspx?TopicID="+id;
}

function BrowseSite()
{
	var id = document.getElementById("SiteSelect").value;
	if(id ==1)
		top.location.href = '/Workflow/default.aspx';
}

function Search(url)
{
	var searchContent = escape(document.getElementById("search").value);
	searchContent = URLEncode(searchContent);
	if(searchContent != "")
	{
		//top.location.href="_layouts/OSSSearchResults.aspx?k="+searchContent +"&cs=This%20Site&u=http%3A%2F%2Fp627%3A10001"
		//top.location.href=url + "/" + strBUName + "/Search/SearchAll.aspx?SearchMore=0&Flag=0&SearchBy=Keyword&SearchFor="+searchContent
		top.location.href=url + "/" + strBUName + "/Search/Search.aspx?SearchMore=0&Flag=0&SearchBy=Keyword&SearchFor="+searchContent
	}
}

function StopPostBack(e)
{
    if (window.event)
            {
		        event.returnValue=false;
    		    
		        return false;
	        }
	        else
	        {
	
		        e.preventDefault();
	        }

}
function fnTrapKD(btn, event)
{

  if (event.keyCode == 13)
  {

    StopPostBack(event);
    document.getElementById(btn).click();
  

  }


}

function fnTrapKD1(btn, event)
{
	
  if (event.keyCode == 13)
  {

   StopPostBack(event);
   document.getElementById(btn).onclick();
  

  }


}

function SearchMore(url)
{
	
	
		//top.location.href="_layouts/OSSSearchResults.aspx?k="+searchContent +"&cs=This%20Site&u=http%3A%2F%2Fp627%3A10001"
		//top.location.href=url + "/" +  strBUName + "/Search/SearchAll.aspx?Flag=0&SearchBy=Keyword&SearchFor=&SearchMore=1";
	top.location.href=url + "/" +  strBUName + "/Search/Search.aspx?Flag=0&SearchBy=Keyword&SearchFor=&SearchMore=1";
}


function RemoveText()
{
	document.getElementById("search").value="";
	document.getElementById("search").className='search1';
	

	
	
}





//MyCCH Page Links
function CreateCCHLink()
{
	var obj = document.getElementById("MyCCHMenu");
	var strList = "";
	var strMyCCHText = (MyCCHLangText)? MyCCHLangText : "My CCH";
	if(obj != null)
	{
		strList += "<table cellpadding='0' cellspacing='0' bgcolor='#f6f7f9' style='width: 150px; height: 151px; border:#d1d1d2 1px solid;'>";
		strList += "<tr><td align='left' class='csbrowse' style='width: 150px; height: 17px; padding-top:5px;'>"+strMyCCHText+" : </td></tr>";
		strList += "<tr><td valign='top' style='padding-left:5px'><table cellpadding='0' cellspacing='0' border='0' >";
		for(var i=1; i< obj.options.length; i++)
		{
			//alert(obj.options[i].selected)
			if(obj.options[i].selected)
				strList += "<tr><td align='middle' style='width:15px'><img alt='sqr' border='0' src='/images/blackarrow_right.gif' align='absmiddle' /></td><td align='left' style='width: 150px; height:10px'> <span class='accDetails'><a href='"+obj.options[i].value+"'>"+obj.options[i].text+"</a></span></td></tr>";
			else
				strList += "<tr><td align='middle' style='width:15px'><img alt='sqr' border='0' src='/images/square.gif' align='absmiddle'/> </td><td align='left' style='width: 150px; height:10px'><span class='mainLinks'><a href='"+obj.options[i].value+"'>"+obj.options[i].text+"</a></span></td></tr>";

		}
		strList += "</table></td></tr></table>";
	}
	document.getElementById("MyCCHLinks").innerHTML = strList;
}

//Email Check
var validationMessage = "";
function check_email_entry (in_email) {
	validationMessage = "";
	var emailStr = in_email;
	var email_len = emailStr.length;
	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 +")*$");
	
	if (email_len > 0) {
		var matchArray = emailStr.match(emailPat);
		if (matchArray == null) {
			//alert("The Email address seems incorrect (check @ and .'s)");
			validationMessage = "The Email address seems incorrect (check @ and .'s)";
			return(false);
		}
	
		var user = matchArray[1];
		var domain = matchArray[2];
		if (user.match(userPat) == null) {
			//alert("The Email username doesn't seem to be valid.");
			validationMessage = "The Email 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("Email Destination IP address is invalid!");
					validationMessage = "Email Destination IP address is invalid!";
					return(false);
				}
			}
			return(true);
		}
	
		var domainArray = domain.match(domainPat)
		if (domainArray == null) {
			//alert("The Email domain name doesn't seem to be valid.");
			validationMessage = "The Email domain name doesn't seem to be valid.";
			return(false);
		}
	
		var atomPat = new RegExp(atom,"g")
		var domArr = domain.match(atomPat)
		var len = domArr.length
		if (domArr[domArr.length - 1].length < 2 || domArr[domArr.length - 1].length > 4) {
			//alert("The Email address must have a valid domain, or two letter country.");
			validationMessage = "The Email address must have a valid domain, or two letter country.";
			return(false);
		}
	
		if (len < 2) {
			//alert("This Email address is missing a hostname!");
			validationMessage = "This Email address is missing a hostname!";
			return(false);
		}
	} else {
		//alert("Please enter a registered email address.");
		validationMessage = "Please enter a registered email address.";
		return(false);
	}
	return(true);
}


 function OpenPopUp(strurl)
 {
 
   testwindow= window.open (strurl, "mywindow",
    "resizable=1,scrollbars=1,width=600,height=600,left=0,top=0");

      //testwindow= window.open (strurl, "mywindow",
    //"scrollbars=1,width=600,height=600,left=0,top=0");
//testwindow.moveTo(0,0);
}

function trimString (str) {
	  str = this != window? this : str;
	  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
	}
	
	
function clickButton(e,buttonId)
{ 
  var bt = document.getElementById(buttonId);   
     if (typeof bt == 'object'){                 
           if(navigator.appName.indexOf("Netscape")>(-1)){ 
                 if (e.keyCode == 13){                 
                       bt.click();
                       return false; 
                 } 
           } 
           if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){                 
                 if (event.keyCode == 13){                  
                      bt.click();
                       return false; 
                 } 
           } 
     }

}  

function CreateGeneralMenu()
{
	if(TopicCategoryMenu)
	{
		var MenuList = "";
		MenuList += "<table cellpadding='0' cellspacing='0' border='0' width='100%'>";
		MenuList += "<tr class='topMenu'>";
		if (TopicCategoryMenu.length > 0 )
		{
			var width = 16;
			var intSpanCount = 0;
			for(var i =0 ; i < TopicCategoryMenu.length; i++)
			{
				var id = TopicCategoryMenu[i][0][1];
				var TopicName = TopicCategoryMenu[i][0][0];
	                    
	            if (TopicName.length < 10) width = TopicName.length + 5; 
	            else width = 16;
	            var strStyle = " width='" + width + "%'";
	
				intSpanCount++;
				if (intCurrentTopic != id)// || (intCurrentTopic != -1 && intCurrentCategory != -1)) 
				{
					MenuList += "<td " + strStyle + " align=left height='23' bgcolor='#666666' class='tax'  id='td_" + id + "'>";
					MenuList += "<span id='span" + intSpanCount + "' style='background-color:#0066CC' onmouseover='MM_showHideLayers(\"TopicMouseOver" + id + "\",\"\",\"show\");' onmouseout='alert();'></span>";
					MenuList += "<div onclick='ShowTopic(" + id + ",\"" + strHost + "\")'>";
					MenuList += "<div  style='text-align:center;'>&nbsp;&nbsp;<img id='img" + id + "' src='/images/pink_bullet.gif' style='vertical-align:absmiddle' alt='' /><span id='TopicMouseOver" + id + "'  onmouseover='MM_showHideLayers(\"Topic" + id + "\",\"\",\"show\");changeClassName(this," + id + ");' onmouseout='MM_showHideLayers(\"Topic" + id + "\",\"\",\"hide\");restoreClassName(this," + id + ");'> &nbsp;" + TopicName + " </span></div>";
					
					if (TopicCategoryMenu[i].length > 1)
					{
						MenuList += "<div id='Topic" + id + "' style='z-index:10001' class='Tax_1' onmouseover='MM_showHideLayers(\"Topic" + id + "\",\"\",\"show\");changeClassName(this," + id + ");' onmouseout='MM_showHideLayers(\"Topic" + id + "\",\"\",\"hide\");restoreClassName(this," + id + ");'>";
						MenuList += "<div><img src='/images/shim.gif' height='5px' alt=''''/></div>";
						var intLayerWidth = 180;
						if (width == 16) intLayerWidth = 203;
						MenuList += "<div style='border:1px solid #000;width:"+intLayerWidth +"'>	";
						
						MenuList += "<table width='" + intLayerWidth + "' border='0' cellpadding='3' cellspacing='0' bgcolor='#FFFFFF' class='dropdownMenu'>	";
						MenuList += "<tr>";
						MenuList += "<td width='19' align='left'></td>";
						MenuList += "<td width='121' height='5'></td>";
						MenuList += "</tr>";
						for(var j = 1 ; j < TopicCategoryMenu[i].length; j++)
						{
							//alert(TopicCategoryMenu[i][j])
							var idCategory = TopicCategoryMenu[i][j][1];
							var CategoryName = TopicCategoryMenu[i][j][0];
	
							MenuList += "<tr>";
							MenuList += "<td align='right'><img id='img" + id + idCategory + "' src='/images/dropdownBullet.gif' alt=''/></td>";
							MenuList += "<td> &nbsp;<a class='dropdownMenu' href='http://" + strHost + "/" + strBUName +  "/TopicCategory.aspx?TopicID=" + id + "&amp;CategoryID=" + idCategory + "' onmouseover='changeImage(" + id + "," + idCategory + ");' onmouseout='restoreImage(" + id + "," + idCategory + ")'>" + CategoryName + "</a> </td>";
							MenuList += "</tr>";
						}
						MenuList += "<tr><td height='5' align='center'></td><td></td></tr></table></div></div></div>";
					}
				}
				else
				{
					if(intCurrentCategory>0)
						MenuList += "<td height='23' " + strStyle + " align=center style='vertical-align:absmiddle' class='tax'  bgcolor='#292929'>&nbsp;&nbsp;<img id='img" + id + "' border='0' src='/images/pink_bullet.gif' style='vertical-align:absmiddle; text-align:center' alt='''' /> &nbsp; <a href='http://" + strHost+ "/" + strBUName +  "/TopicCategory.aspx?TopicID=" + id + "' style='text-decoration:none;color:#FFFFFF;'>" + TopicName + "</a> ";
	                else
						MenuList += "<td height='23' " + strStyle + " align=center style='vertical-align:absmiddle' class='tax' bgcolor='#292929'>&nbsp;&nbsp;<img id='img" + id + "' src='/images/pink_bullet.gif' style='vertical-align:absmiddle; text-align:center' alt='''' /> &nbsp;" + TopicName + " ";
						
				}
				MenuList += "</td>";
			}
		}
		obj = document.getElementById("TopicCategoryMenuLayer");
		if(obj) obj.innerHTML = MenuList;
		obj = document.getElementById("ContentHeaderImage");

		if(obj)
		{ 
			//alert(obj.src);
			// if language is other than en-US
			var imgSrc = obj.src;
			//if(!obj.src.indexOf("/images/"+ImagePrefix)>(-1))
			obj.src = imgSrc.replace("/images/","/images/"+ImagePrefix);
		}

	}
}
function CreateSolutionMenu()
{
	if(TopicCategoryMenu)
	{
		var MenuList = "";
		MenuList += "<table cellpadding='0' cellspacing='0'>";
		MenuList += "<tr class='topMenu'>";
		if (TopicCategoryMenu.length > 0 )
		{
			var width = 16;
			var intSpanCount = 0;
			for(var i =0 ; i < TopicCategoryMenu.length; i++)
			{
				var TopicName = TopicCategoryMenu[i][0];
				var strStyle = " width='190px' align=left ";
				intSpanCount++;
				if(strDefaultURL != TopicCategoryMenu[i][1].toLowerCase())
				{
					MenuList += "<td " + strStyle + " height='23' valign='middle'  bgcolor='#666666'  class='tax'  id='td_" + i + "'>";
					MenuList += "<span id='span" + intSpanCount + "' style='background-color:#0066CC' onmouseover='MM_showHideLayers(\"TopicMouseOver" + i + "\",\"\",\"show\");' onmouseout='alert();'></span>";
					MenuList += "<div onclick='ShowSolution(\"" + TopicCategoryMenu[i][1] + "\",\"" + strHost + "\")'>";
					MenuList += "<div  style='text-align:center'><span id='TopicMouseOver" + i + "'  onmouseover='MM_showHideLayers(\"Topic" + i + "\",\"\",\"show\");changeClassName(this," + i + ");' onmouseout='MM_showHideLayers(\"Topic" + i + "\",\"\",\"hide\");restoreClassName(this," + i + ");' style='vertical-align:middle'> &nbsp;&nbsp;<img id='img" + i + "' src='/images/pink_bullet.gif' style='vertical-align:middle' alt='' /> &nbsp;" + TopicName + " </span></div>";
				}
				else
				{
					MenuList += "<td  width='190px' height='23' valign='middle' align='center'  bgcolor='#292929'  class='tax'>&nbsp;&nbsp;<img id='img" + i + "' src='/images/pink_bullet.gif' style='vertical-align:absmiddle; text-align:center' alt='''' /> &nbsp;" + TopicName + " ";
				}
				MenuList += "</td>";
			}
		}
		obj = document.getElementById("TopicCategoryMenuLayer");
		if(obj) obj.innerHTML = MenuList;
	}

}

function ShowSolution(id,httphost)
{
	top.window.location.href="http://" + httphost+ "/" + strBUName +  "/"+id;
}


function show_hide_column(col_no, show)
 {

    var stl;
    if (show!=0) stl = 'block'
    else         stl = 'none';
if(show==0)
{
    var tbl  = document.getElementById('tblCart');
    var rows = tbl.getElementsByTagName('tr');
    var colctr=tbl.getElementsByTagName('tr')[0].getElementsByTagName('td').length 

    for (var row=0; row<rows.length;row++) {
      var cels = rows[row].getElementsByTagName('td')
    var i=col_no;
    if(cels.length<colctr) i=i-1;
      cels[i].style.display=stl;
      }
    }
  }
  
function URLEncode (clearString) 
{
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}


