// / / / / / / Menu Javascript
var time = 3000;
var numofitems = 7;

//menu constructor
function menu(allitems,thisitem,startstate){ 
  callname= "gl"+thisitem;
  divname="subglobal"+thisitem;  
  this.numberofmenuitems = 7;
  this.caller = document.getElementById(callname);
  this.thediv = document.getElementById(divname);
  this.thediv.style.visibility = startstate;
}

//menu methods
function ehandler(event,theobj){
  for (var i=1; i<= theobj.numberofmenuitems; i++){
    var shutdiv =eval( "menuitem"+i+".thediv");
    shutdiv.style.visibility="hidden";
  }
  theobj.thediv.style.visibility="visible";
}
				
function closesubnav(event){
  if ((event.clientY <73)||(event.clientY > 138)){
    for (var i=1; i<= numofitems; i++){
      var shutdiv =eval('menuitem'+i+'.thediv');
      shutdiv.style.visibility='hidden';
    }
  }
}


function popWin()
{
	var args;
	var win;
  args = popWin.arguments;
  win = window.open(args[0],args[1],args[2]);
  win.focus();
}


function mdDisagree()
{
  window.location="/support/";
}


//	Cookie Handling ///////////////////////////////////

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return "";
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function buttonWrite() {

	if (getCookie("Status") == "Logged")
	{ // code for logout button
		document.write("<a href=\"javascript:popCenteredWindow('/logout.html','Logout','460','300','scrollbars=0,resizable=0')\" class=\"vSmall_Red_Bold_Link\">LOGOUT</a>&nbsp;<img src=\"/images/h_bullet2.gif\" align=\"absbottom\">&nbsp;<a href=\"/mycnxt/\"><img src=\"/images/mycnxt_btn.gif\" align=\"absbottom\"></a>");
	} else
	{ // code for login button
		document.write("<a href=\"javascript:popCenteredWindow('/login.html','Login','460','300','scrollbars=0,resizable=0')\" class=\"vSmall_Red_Bold_Link\">LOGIN</a>&nbsp;<img src=\"/images/h_bullet2.gif\" align=\"absbottom\">&nbsp;<a href=\"/mycnxt/\"><img src=\"/images/mycnxt_btn.gif\" align=\"absbottom\"></a>");
	}
	
}

function statusWrite() {

	if (getCookie("Status") == "Logged")
	{
		// BACKUP --> document.write("<span class=\"Small_DkGray\">Welcome, " + getCookie("FName") + " " +  getCookie("LName") + "</span>&nbsp;<img src=\"http://www.conexant.com/images/h_bullet2.gif\" width=\"12\" height=\"12\" border=\"0\" align=\"absbottom\">&nbsp;");
		document.write("<span class=\"Small_DkGray\">Welcome, " + getCookie("FName") + "</span>&nbsp;<img src=\"http://www.conexant.com/images/h_bullet2.gif\" width=\"12\" height=\"12\" border=\"0\" align=\"absbottom\">&nbsp;");
	} else
	{
		document.write("&nbsp;&nbsp;");
	}

}


// ===== Site Search Function =====
function siteSearch()
{
	// ===== Site Search =====
//		document.write("<p>Site Search</p>");
//		document.write("<form name=\"SiteSearch\" method=\"POST\" action=\"/s/results.jsp\">");	
//		document.write("<input type=\"hidden\" name=\"section\" value=\"conexant_com_general\">");
//		document.write("<input type=\"hidden\" name=\"start\" value=\"0\">");
//		document.write("<input type=\"hidden\" name=\"size\" value=\"10\">");
//		document.write("<input type=\"text\" name=\"q\" class=\"text\"> ");
//		document.write("<input type=\"image\" class=\"submit\" src=\"/images/_submit_arrow.gif\">");
//		document.write("</form>");
	// ===== End Site Search =====		
	// ===== Product Search =====
		document.write("<p>Search:</p>");
		document.write("<form name=\"ProdSearch\" method=\"POST\" action=\"/s/sresults.jsp\">");	
		////document.write("<input type=\"hidden\" name=\"section\" value=\"conexant_com_products\">");
		//document.write("<input type=\"hidden\" name=\"section\" value=\"default_collection\">");
		document.write("<input type=\"hidden\" name=\"section\" value=\"conexant_com\">");
		document.write("<input type=\"hidden\" name=\"start\" value=\"0\">");
		document.write("<input type=\"hidden\" name=\"size\" value=\"10\">");
		document.write("<input type=\"hidden\" name=\"run\" value=\"Y\">");
		document.write("<input type=\"text\" name=\"q\" class=\"text\"> ");
		document.write("<input type=\"image\" class=\"submit\" src=\"/images/_submit_arrow.gif\">");
		document.write("</form>");
	// ===== End Product Search =====

}


// ===== Begin Registration Validation Form

function validateRegistration(){
	var error_str='';
	var error_focus_set=0;


	// First Name field must contain data
		var str=document.newRegistration.FirstName;
		if (str.value.length<1){
			error_str+='\n-Please enter your First Name.';
			if (!error_focus_set) error_focus_set=str;
		}
		
	// Last Name field must contain data
		var str=document.newRegistration.LastName;
		if (str.value.length<1){
			error_str+='\n-Please enter your Last Name.';
			if (!error_focus_set) error_focus_set=str;
		}
	
	// Company field must contain data
		var str=document.newRegistration.CompanyName;
		if (str.value.length<1){
			error_str+='\n-Please enter your Company Name.';
			if (!error_focus_set) error_focus_set=str;
		}
	
	// Phone Number field must contain data
		var str=document.newRegistration.PhoneNumber;
		if (str.value.length<1){
			error_str+='\n-Please enter your Phone Number.';
			if (!error_focus_set) error_focus_set=str;
		}
		
	/*  removed.  Email is now embedded and should not be checked
	// E-Mail Address field must contain data
		var str=document.newRegistration.EmailAddress;
		if (str.value.length<1){
			error_str+='\n-Please enter your primary E-Mail Address.';
			if (!error_focus_set) error_focus_set=str;
		}
	*/
		
	//Password field should equal to PasswordChk field
		var str1 = document.newRegistration.Password;
		var str2 = document.newRegistration.PasswordChk;
		
		if ((str1.value.length<1)&&(str2.value.length<1)){
			error_str+='\n-Please enter your desired Password.';
			if (!error_focus_set) error_focus_set=str;
		}
		if (str1.value!=str2.value){
			error_str+='\n-The two passwords are not the same.';
			if (!error_focus_set) error_focus_set=str;
		}
		
	//Password field can only contain 0~9, a~z, A~Z
		var str1 = document.newRegistration.Password;
		ok = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		var foundError=0;
		
		for(i=0; i < str1.value.length ;i++){
			if(ok.indexOf(str1.value.charAt(i))<0){ 
				foundError++;
			}	
		} 
		
		if (foundError>0){
			error_str+='\n-Password contains invalid character(s).';
			if (!error_focus_set) error_focus_set=str;
		}
		
	
	/*
	//Challenge Question field must contain data
		var index = document.newRegistration.ChallengeQuestion.options.selectedIndex;
		var str=document.newRegistration.ChallengeQuestion[index];
		if (str.value.length<1){
			error_str+='\n-Please select a Challange Question.';
			if (!error_focus_set) error_focus_set=str;
		}
	*/
		
	// Hint-Answer  field must contain data
		var str=document.newRegistration.ChallengeAnswer;
		if (str.value.length<1){
			error_str+='\n-Please enter your Challenge Answer.';
			if (!error_focus_set) error_focus_set=str;
		}
	
		/*
		//PLU field must contain data
		var index = document.newRegistration.PLU.options.selectedIndex;
		var str=document.newRegistration.PLU[index];
		if (str.value.length<1){
			error_str+='\n-Please select a Product Line of Interest.';
			if (!error_focus_set) error_focus_set=str;
		}
		*/
	
	// submit or display errors
		if (error_str.length>0){
			alert('Please correct the following:\n'+error_str);
			if (error_focus_set) error_focus_set.focus();
			return;
		}
		else{
			document.newRegistration.submit();
		}
}

// ===== End Registration Validation Form

// ===== Begin Validation for Password Recovery ====

function validatePwdRecovery(){
	var str = document.pwdRecovery.EmailAddress;
	if (str.value.length < 1){
		alert('Please enter your registered e-mail address.');
		str.focus();
	}
	else{
		document.pwdRecovery.submit();
	}
}

function validateCQ(){
	var str = document.cq.ChallengeAnswer;
	if (str.value.length < 1){
		alert('Please enter an answer to the challenge question displayed.');
		str.focus();
	}
	else{
		document.cq.submit();
	}
}

// ===== End Validation for Password Recovery =====


// ===== Pop Centered Window: Parameters[URL,Title,Width,Height,Features(opt.)] =====

function popCenteredWindow(URL,Title,Width,Height,Features)
{
	var winURL = URL;
	var winTitle = Title;
	var winWidth = Width;
	var winHeight = Height;
	var x = (screen.width - winWidth)/2;
	var y = (screen.height - winHeight)/2;
	var setWindow = 'width=' + winWidth + ',height=' + winHeight + ',left=' + x + ',screenX=' + x + ',top=' + y + ',screenY=' + y;
	var winFeatures = "";
	if(Features == ""){
		winFeatures = setWindow;}
	else{
		winFeatures = setWindow + ", " + Features;}

	window.open(winURL,winTitle,winFeatures);
}

//========= New Window =======
function NewWindow(mypage,myname,w,h,scroll,pos)
{
	var win=null;
	if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
	else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
}

// ===== End Pop Centered Window =====
function openBlock(window_title,blockDiagUrl,code,psp_URL,width,height,fastpreview)
{ 
	//var url = getPreviewUrl('../components/hot.jsp?image='+blockDiagUrl+'&code='+code,fastpreview);

	ajaxwin=dhtmlwindow.open('ajaxbox','ajax',blockDiagUrl,window_title, 'width=450px,height=300px,left=50px,top=100px,resize=0,scrolling=1');
	/*dcsMultiTrack('DCS.dcsuri',blockDiagUrl,'WT.ti','Block Diagram View','DCS.dcsref',psp_URL,'WT.dl','1');*/
	return false ;
}
