var popUpWin=0;
function clearBox()
{
	//alert (document.SignUp.su_professionalSummary.value);
	//document.write(document.SignUp.su_professionalSummary.value);
	var is_summary=document.SignUp.su_professionalSummary.value.indexOf('-------------- REMOVE THIS LINE  ------------------');
	var is_summary1=document.SignUp.su_professionalSummary.value.indexOf('SAMPLE');
	if (is_summary != -1 || is_summary1 != -1)
	{
		document.SignUp.su_professionalSummary.value = "";
	}
}

function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin )
  {
	//  if (!popUpWin.closed)
	//alert('');
	    popUpWin.close();
  }
 popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  
}

function SelectOption(OptionListName, ListVal)
{	
	
	for (i=0; i < OptionListName.length; i++)
	{
		if (OptionListName.options[i].value == ListVal)
		{
			OptionListName.selectedIndex = i;
			break;
		}
	}
}

function SelectMultiOption(OptionListName, ListVal)
{	
	var valList = ListVal.split("##");
	
	for (j=0; j<valList.length; j++)
	{
	  newListVal = valList[j];
	  for (i=0; i < OptionListName.length; i++)
	  {
		if (OptionListName.options[i].value == newListVal){			
			OptionListName.selectedIndex = i;
		}
	  }
	}
}

function calcCharLeft(form,element){
		clipped = false
		maxLength = 600
        if (element.value.length > maxLength) { 
	        element.value = element.value.substring(0,maxLength)
		    charleft = 0
		    clipped = true
        } else {
			charleft = maxLength - element.value.length
		}
        form.charsLeft.value = charleft
        return clipped
}

function textKey(form,element){
	supportsKeys = true
	calcCharLeft(form,element)
}


function calcCharLeft1(form,element,maxLength){
		clipped = false
        if (element.value.length > maxLength) { 
	        element.value = element.value.substring(0,maxLength)
		    charleft = 0;
		    clipped = true;
        } else {
			charleft = maxLength - element.value.length
		}
        form.charsLeft.value = charleft;
        return clipped;
}

function textKey1(form,element,maxlength){
	supportsKeys = true
	calcCharLeft1(form,element,maxlength)
}


function stickNote(message, divID, browser, domain)
{
	// message = Message to print inside Note
	// divID = Span where the note will display
	// browser = Users Browser
	var noteBox = "<table width='765' cellspacing='0' cellpadding='1'><tr><td><table width='765' cellpadding='1' cellspacing='0'><tr><td><table width='765' cellspacing='0' cellpadding='1'><tr><td bgcolor='#FF8A00'><table width='765' cellpadding='2' cellspacing='0' bgcolor='#FFF9CE'><tr><td width='748' align='left'>"+message+"</td><td width='10' align='right' valign='top'><a href='javascript:;' onClick=\"closeStickNote('"+divID+"', '"+browser+"', '"+domain+"');\"><img src='images/informationbar_iconclose.gif' width='13' height='13' border='0' /></a></td></tr></table></td></tr></table></td><td width='1' rowspan='2' bgcolor='#CCCCCC'></td></tr><tr><td height='2' bgcolor='#CCCCCC'></td></tr></table></td></tr><tr><td height='5'></td></tr></table>";
	document.getElementById(divID).innerHTML = noteBox;
	return; 
}
function stickNote1(message, divID, browser)
{
	// message = Message to print inside Note
	// divID = Span where the note will display
	// browser = Users Browser
	var noteBox = "<table width='100%' cellspacing='0' cellpadding='1'><tr><td height=5></td></tr><tr><td><table width='100%' cellpadding='1' cellspacing='0'><tr><td><table width='100%' cellspacing='0' cellpadding='1'><tr><td bgcolor='#FF8A00'><table width='100%' cellpadding='2' cellspacing='0' bgcolor='#FFF9CE'><tr><td width='99%' align='left'>"+message+"</td><td width='10' align='right' valign='top'></td></tr></table></td></tr></table></td><td width='1' rowspan='2' bgcolor='#CCCCCC'></td></tr><tr><td height='2' bgcolor='#CCCCCC'></td></tr></table></td></tr><tr><td height='5'></td></tr></table>";
	document.getElementById(divID).innerHTML = noteBox;
	return; 
}

function closeStickNote(divID, browser, domain)
{
	if (browser == "NOTIE")
		document.getElementById(divID).innerHTML = "";
	else
		document.getElementById(divID).style.display = "none";
		
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+1*24*60*60*1000);
	//Today.setTime(nomilli);
	UTCstring = Today.toUTCString();

	document.cookie = "stickNote=Off;expires="+UTCstring+";path=/; domain="+domain;
}

function closeMsgBoxes(divID)
{
		document.getElementById(divID).innerHTML = "";
}

function showProcessBar(spanID)
{
	document.getElementById(spanID).innerHTML = "<img src='images/working.gif' width='16' height='16' align='absmiddle' /> <span class='maroon10NB'> PROCESSING, PLEASE WAIT... </span>";
}

function hideProcessBar(spanID)
{
	document.getElementById(spanID).innerHTML = "";
}

function outputProcessing(){
	return "<table cellpadding='0' cellspacing='0' width='100%' border=0><tr><td height='20' colspan='2' align='left' width='100%'>&nbsp;<img src='images/working.gif' width='16' height='16' align='absmiddle' /> <span class='maroon10NB'> PROCESSING, PLEASE WAIT... </span></td></tr></table>";
}

function outputProcessing1(spanID)
{
	document.getElementById(spanID).innerHTML = "<img src='images/working.gif' width='16' height='16' align='absmiddle' /> <span class='maroon10NB'> PROCESSING... </span>";
}

function outputError(str){
	return "<table cellpadding='0' cellspacing='0' bgcolor='#b90000' width='100%'><tr><td height='20' colspan='2' align='left'   valign='top' width='3%'><img src='images/16_warn.gif' width='16' height='16' hspace=3 vspace=2 /></td><td class='white11' width='97%' align=left> "+str+"</td></tr></table>";
}

function outputMessage(str){
	return "<table cellpadding='0' cellspacing='0' bgcolor='#87BF00' width='100%'><tr><td height='20' colspan='2' align='left'   valign='top' width='3%'><img src='images/16_warn.gif' width='16' height='16' hspace=3 /></td><td class='black11' width='97%' align=left> "+str+"</td></tr></table>";
}

var nav = window.Event ? true : false;
function onKeyPressAllowEnter(e){
	if (nav) {
		  if (e.which == 13 &&  e.target.type == 'text') { 
			return true; 
		  }
		  	return false;
	} else {		  
		  if (event.keyCode == 13 && event.srcElement.type == 'text'){
			return true;
		  }
		  return false;
	}
}

function showHide(show,hide){

	show = show.split('#');
	hide = hide.split('#');
	
	if(hide!='null'){
		for(i=0; i<hide.length; i++){
			if(document.getElementById(hide[i]))
				document.getElementById(hide[i]).style.display = 'none';
			//else
				//alert('Unable to hide: '+hide[i]);
		}
	}
	if(show!='null'){
		for(i=0; i<show.length; i++){
			if(document.getElementById(show[i])){
				if (show[i]=='pkH' && show[i]=='pkM')
					document.getElementById(show[i]).style.display = 'inline';
				else
					document.getElementById(show[i]).style.display = '';
			}
			//else
				//alert('Unable to show: '+show[i]);
		}
	}
}

function trim(str){
 return str.replace(/^\s*|\s*$/g,"");
}

function number_format ( n, sSep ) {

	n = n.toString ( );

	var p1, p2, p3;
	var sSep = ( sSep == null ? ',' : sSep );

	n = n.split ( '.' );
	p1 = n [ 0 ];
	p2 = ( n [ 1 ] == null ? '' : '.' + n [ 1 ] );
	p3 = '';

	for ( var i = p1.length-1 ; i >= 0; i -- ) {
		p3 += p1.charAt ( p1.length - i - 1 );
		if ( i % 3 == 0 && i != 0 ) p3 += sSep;
	}

	return p3 + p2;

}

function randomString(strLen) {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = strLen;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

function msgWithBorder(id,str,msgType,marginTop,marginBottom,multiLineMsg){
	
	var row = ''
	var valignIcon = 'middle';
	
	if(msgType == 'error')
		var bgClr = '#b90000';
	else if(msgType == 'success')
		var bgClr = '#87BF00';
	
	if(multiLineMsg){
		row = '<tr><td height=4></td></tr>';
		valignIcon = 'top';
	}

	var str = "<table width='100%' cellpadding='2' cellspacing='0' style='border: 1px solid #cccccc;margin-top: "+marginTop+"px; margin-bottom: "+marginBottom+"px;'><tr><td><table cellpadding='0' cellspacing='0' bgcolor='"+bgClr+"' width='100%' style='padding:5px 0px;' >"+row+"<tr><td height='20' colspan='2' align='left'   valign='"+valignIcon+"' width='3%'><img src='images/16_warn.gif' width='16' height='16' hspace=3 /></td><td class='white11' width='94%' align=left> "+str+"</td><td width='3%' valign='"+valignIcon+"'><a href='javascript:;' onClick=\"document.getElementById('"+id+"').innerHTML=''\"><img src='images/informationbar_iconclose.gif' border='0' hspace=4 /></a></td></tr>"+row+"</table></td></tr></table>";
	document.getElementById(id).innerHTML = str;
}

function validEmail(emailVal){
	regex = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;

	if( !regex.test( emailVal ) )
		return false;
	
	return true;
}

function validURL(subDom,dom,minLen){
	urlRegex = /^http:\/\/[a-zA-Z0-9-]+$/;

	subDom = trim(subDom);
	dom = trim(dom);
	
	if(subDom=='' || dom=='')
		return 'empty';
	
	if(subDom.length<minLen)
		return 'lessSize';
	
	if( !urlRegex.test( subDom ) )	
		return 'invalid';

	return 'valid';
}

function checkBrowse(e)
{
	if (e.keyCode != '')	return false;
}

function validImgExt(val) {
        var isOK = false;
         if ((val != '') && (val > 1)) 
             isOK = true;
         else
            isOK = false;

        var fileName = val.toLowerCase();

        if((fileName.indexOf('.jpeg') != -1) ||            
            (fileName.indexOf('.jpg') != -1) ||
            (fileName.indexOf('.gif') != -1) ||
            (fileName.indexOf('.png') != -1) ) {
            isOK = true;
        }
        else            
            isOK = false;

         return isOK;
}

// simplePreload( '01.gif', '02.gif' );
function preImg(){ 
  var args = preImg.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++){
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

function change2Multiple(id, id_, type)
{
	//alert(id+" "+id_+" "+type);
	if (type == "M")
	{
		$SDDS(id_+type, 'none');
		$SDDS(id_+'S', '');
		document.getElementById(id).multiple=true;
		document.getElementById(id).style.height='80px';
	}
	else if (type == "S")
	{
		$SDDS(id_+type, 'none');
		$SDDS(id_+'M', '');	
		document.getElementById(id).multiple=false;
		document.getElementById(id).style.height='';
	}
	//$SIH(id_,msg);
}


// Start Auto completer for Degree Title and Major Subjects
function loadAutoCompList(inpName,hTxt,funName,index,addLIID)
{
	if(typeof(index) == 'undefined') index='';
	//="Type here to search a company"
	jQuery(function() {  
			jQuery("#"+inpName).tokenInput({
				stng:{ 
					url: "jx/misc.php", 
					hintText: hTxt,
					noResultsText: "No match found",
					searchingText: "Searching...",
					searchDelay: 180,
					width:jQuery("#"+inpName).parent().css('width'),
					inputwidth:jQuery("#"+inpName).parent().css('width'),
					cntList: 1,
					callF:funName,
					ctrlName: inpName,
					allowNew: 'Yes',
					index: index,
					addLIID:addLIID
				}
			});			
	});
}

function showTitleMajor(index,addID4Deg)
{  
  var inx = index;
  if(typeof(inx) == 'undefined') inx='';   
  
  if(jQuery('#degree'+inx).val()=='')
  {
	jQuery('#degTitleArea'+inx).hide();
	jQuery('#dd4M'+inx).hide();
	jQuery('#majorArea'+inx).show();	
	jQuery('#autoComp4Major'+inx).show();
  } 
  else 
  { 
	
	jQuery('#degTitleArea'+inx).show();
	if(jQuery('#degree'+inx).val() == 'Matriculation')
	{
	 
	 jQuery.ajax({
				type:"POST",
				url:'jx/misc.php', 
				data:({f:'loadMajors',level:jQuery('#degree'+inx).val()}), 				
				success: function(data){					
				jQuery('#majorTitID4Cus'+inx).html(data);
				jQuery('#majorTitID4Cus'+inx).show();
				jQuery('#dd4M'+inx).show();
				jQuery('#majorArea'+inx).show();
				
				}
	 });
	
	 jQuery('#dd4M'+inx).show();
	 jQuery('#autoComp4Major'+inx).hide();
	} 
	else if(jQuery('#degree'+inx).val() == 'Non-Matriculation')
	{	  
	  jQuery('#majorArea'+inx).hide();	
	}
	else
	{	 
	 jQuery('#majorArea'+inx).show();	
	 jQuery('#dd4M'+inx).hide();
	 jQuery('#autoComp4Major'+inx).show();
	}
  } 
	
	var id = jQuery('#profDegTit'+inx).val();
	id = id.substring(0,id.length-1);	
	if(id !='')
	{
		//console.log('here');
		jQuery('#spmkmDegTitle'+inx+' .token-input-input-token-facebook input').show();
		jQuery('#spmkmDegTitle'+inx).find('li#li_'+id+addID4Deg).remove();
		jQuery('#profDegTit'+inx).val('');
		jQuery('#degTitID'+inx).val('');
		jQuery('#degTit'+inx).val(''); //change
	}
}

function upEduInfo(degLF,degTF,addID4Deg,addID4Maj)
{					
			var addIDDeg = addID4Deg;
            if(typeof(addID4Deg) == 'undefined') addIDDeg='';
			
			var addIDMaj = addID4Maj;
            if(typeof(addID4Maj) == 'undefined') addIDMaj='';
			
			var levl = jQuery('#'+degLF).val();
			jQuery('#degTitID').val(jQuery('#profDegTit').val());
			var degTitID = jQuery('#degTitID').val();
			if(degTitID!='')
			{
				var recordID = degTitID.substring(0,degTitID.length-1)+addIDDeg;				
				jQuery('#'+degTF).val(jQuery('#spmkmDegTitle #li_'+recordID).children('p').html());
			}
			else			
				jQuery('#'+degTF).val(jQuery('#spmkmDegTitle #tmpTxt').val());
			
			
			if(levl=='Non-Matriculation')
			{
		      jQuery('#majorTitID').val('');
			  jQuery('#majorTit').val('');			   
			}
			else if(levl=='Matriculation')
			{	 
			  
			  jQuery('#majorTitID').val(jQuery('#majorTitID4Cus').val());
			  jQuery('#majorTit').val('');
			}
			else
			{
			 jQuery('#majorTitID').val(jQuery('#profMajorSub').val());
			 var mSubID = jQuery('#majorTitID').val();
			 if(mSubID!='')
			 {
				var recordIDM = mSubID.substring(0,mSubID.length-1)+addIDMaj;  
				jQuery('#majorTit').val(jQuery('#spmkmMajorSub #li_'+recordIDM).children('p').html());
			 }
			 else
				jQuery('#majorTit').val(jQuery('#spmkmMajorSub #tmpTxt').val());
			}
			
		
}

function autoCompSelect(autoFName,autoFID,autoFTit,autoAreaID,selTitle,selID,addID)
{
  /*
  if(selID == '')
   selID = tempSelTit;
 
 
  if(typeof(tempSelTit) == 'undefined') tempSelTit='tit';   -->
  */
  //alert(selTitle);
  //alert(selID);
  
  var additionalID = addID;
  if(typeof(addID) == 'undefined') additionalID='';
  
  if(selTitle !='' || selID != '')						   
  {
	if(selID != '')
	{
      selID = selID+additionalID;
	  jQuery('#'+autoAreaID+' ul.token-input-list-facebook').prepend('<li style="width: 95%;" id="li_'+selID+'" class="token-input-token-facebook"><p style="float: left; width: 95%;">'+selTitle+'</p> <span class="token-input-delete-token-facebook" onclick="jQuery(\'#'+autoAreaID+' .token-input-input-token-facebook input\').show(); jQuery(\'#'+autoFName+'\').val(\'\');jQuery(\'li#li_'+selID+'\').remove();jQuery(\'#'+autoFID+'\').val(\'\');jQuery(\'#'+autoFTit+'\').val(\'\');">x</span></li>');						
									
	  jQuery('#'+autoAreaID+' .token-input-input-token-facebook input').hide();		
	}
	else
	{
	  jQuery('#'+autoAreaID+' .token-input-input-token-facebook input').val(selTitle);
	  jQuery('#'+autoAreaID+' .token-input-input-token-facebook input').show();	
	}
  }
	
}
		

// End Auto completer for Degree Title and Major Subjects
