// JavaScript Document
function checkforfile(fileboxvalue,messageid) {
	if(fileboxvalue != ''){
		document.getElementById(messageid).style.visibility = 'visible';
	}else{
		document.getElementById(messageid).style.visibility = 'hidden';
	}
}

function SetOrderClause(val, a_id){
	if(document.getElementById("h_orderby").value == val){
		document.getElementById("h_orderby").value = val + " DESC";
		document.getElementById("h_id").value = a_id;
		document.getElementById("h_class").value = "column_header_desc";
		//document.getElementById("h_action").value = "orderby";
	}
	else{
		document.getElementById("h_orderby").value = val;
		document.getElementById("h_id").value = a_id;
		document.getElementById("h_class").value = "column_header_asc";
		document.getElementById(a_id).className = "column_header_asc";
		//document.getElementById("h_action").value = "orderby";
	}

	document.forms[0].submit();	
}

function ValidateBetweenDates()
{
	err = '';	
	message='';
	if (document.getElementById("From").value=='')
		message='Please input From date/n';
	if (document.getElementById("To").value=='')
		message+='Please input To date';
	if (message !='')
		alert(message);
	else
	{
		document.forms[0].h_action.value='change_filters'; 
		document.forms[0].submit();
	}
		
}


function showhide(id){ 
	if (document.getElementById){ 
		obj = document.getElementById(id); 
		if (obj.style.display == "none"){ 
			obj.style.display = ""; 
		} else { 
			obj.style.display = "none"; 
		} 
	} 
}

function show(id){ 
	if (document.getElementById){ 
		obj = document.getElementById(id); 
		if (obj.style.display == "none") 
			obj.style.display = ""; 
	} 
} 
 
function hide(id){ 
	if (document.getElementById){ 
		obj = document.getElementById(id); 
		if (obj.style.display == "") 
			obj.style.display = "none"; 
		
	} 
} 

function enabled_radiolist()
{
if(document.forms[0].rdo_client_type[1].checked) { document.forms[0].rdo_vat_option[0].disabled=false; document.forms[0].rdo_vat_option[1].disabled=false;}	
}

///options
var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function getNewTeamUsers(menu)
{
	for (i=0; i < menu.options.length; i++)
		document.forms[0].h_users.value += menu.options[i].value +";";
}


function addOption(theSel, theText, theValue)
{
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{ 
  var selLength = theSel.length;
  var deletedValues = new Array();
  deletedValues[deletedValues.length-1] = theSel.options[theIndex].value;
  
  if(selLength>0)
  {
    theSel.options[theIndex] = null;
  }
}

function moveOptions(theSelFrom, theSelTo)
{
  
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  var j;
  
   
	
  
  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  //for(i=selLength-1; i>=0; i--)
  //{
    //if(theSelFrom.options[].selected)
    //{
     // selectedText[selectedCount] = theSelFrom.options[i].text;
      //selectedValues[selectedCount] = theSelFrom.options[i].value;
	  //deleteOption(theSelFrom, i);
      //selectedCount++;
	  selectedText[0] = theSelFrom.options[theSelFrom.selectedIndex].text;
	  selectedValues[0] = theSelFrom.options[theSelFrom.selectedIndex].value;
    //}
  //}

  
  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
	more=false;
	for(j=0; j<=theSelTo.length-1; j++)
	{
		if(theSelTo.options[j].value == selectedValues[0]) 
		{
			alert("This user allready exist in this team!");
			more=true;
		}
	}	
    if(!more)
		addOption(theSelTo, selectedText[0], selectedValues[0]);


  if(NS4) history.go(0);
}



//color picker

function getScrollY()
{
	var scrOfX = 0,scrOfY=0;
	if(typeof(window.pageYOffset)=='number')
	{
		scrOfY=window.pageYOffset;scrOfX=window.pageXOffset;
	}
		else if(document.body&&(document.body.scrollLeft||document.body.scrollTop))
		{
			scrOfY=document.body.scrollTop;scrOfX=document.body.scrollLeft;}
		else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop))
		{
			scrOfY=document.documentElement.scrollTop;
			scrOfX=document.documentElement.scrollLeft;
		}
			return scrOfY;
		}
		
		//document.write("<style type='text/css'>.colorpicker201{visibility:hidden;display:none;position:absolute;background:#FFF;border:solid 1px #CCC;padding:4px;z-index:999;filter:progid:DXImageTransform.Microsoft.Shadow(color=#D0D0D0,direction=135);}.o5582brd{padding:0;width:12px;height:14px;border-bottom:solid 1px #DFDFDF;border-right:solid 1px #DFDFDF;}a.o5582n66,.o5582n66,.o5582n66a{font-family:arial,tahoma,sans-serif;text-decoration:underline;font-size:9px;color:#666;border:none;}.o5582n66,.o5582n66a{text-align:center;text-decoration:none;}a:hover.o5582n66{text-decoration:none;color:#FFA500;cursor:pointer;}.a01p3{padding:1px 4px 1px 2px;background:whitesmoke;border:solid 1px #DFDFDF;}</style>");
		
		function getTop2()
		{
			csBrHt=0;
			if(typeof(window.innerWidth)=='number')
			{
				csBrHt=window.innerHeight;
			}
			else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight))
			{
				csBrHt=document.documentElement.clientHeight;
			}
			else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){csBrHt=document.body.clientHeight;
			}
			
			ctop=((csBrHt/2)-115)+getScrollY();
			return ctop;
			}
			
			var nocol1="&#78;&#79;&#32;&#67;&#79;&#76;&#79;&#82;";
			var clos1="&#67;&#76;&#79;&#83;&#69;";
			//var tt2="&#70;&#82;&#69;&#69;&#45;&#67;&#79;&#76;&#79;&#82;&#45;&#80;&#73;&#67;&#75;&#69;&#82;&#46;&#67;&#79;&#77;";
			//var hm2="&#104;&#116;&#116;&#112;&#58;&#47;&#47;&#119;&#119;&#119;&#46;";
			//hm2+=tt2;
			//tt2="&#80;&#79;&#87;&#69;&#82;&#69;&#68;&#32;&#98;&#121;&#32;&#70;&#67;&#80;";
			
			function getLeft2()
			{
				var csBrWt=0;
				if(typeof(window.innerWidth)=='number')
				{
					csBrWt=window.innerWidth;}
				else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight))
				{
					csBrWt=document.documentElement.clientWidth;
				}
				else if(document.body&&(document.body.clientWidth||document.body.clientHeight))
				{
					csBrWt=document.body.clientWidth;
				}
				
				cleft=(csBrWt/2)-125;
				return cleft;
			}
				
				function setCCbldID2(objID,val)
				{
					document.getElementById(objID).value=val;
				}
				
				function setCCbldSty2(objID,prop,val)
				{
					switch(prop){
						case "bc":
							if(objID!='none')
							{
								document.getElementById(objID).style.backgroundColor=val;
							};
							break;
						case "vs":
							document.getElementById(objID).style.visibility=val;
							break;
						case "ds":
							document.getElementById(objID).style.display=val;
							break;
						case "tp":
							document.getElementById(objID).style.top=val;
							break;
						case "lf":
							document.getElementById(objID).style.left=val;
							break;
						}
					}
function putOBJxColor2(OBjElem,Samp,pigMent)
{
	if(pigMent!='x')
	{
		setCCbldID2(OBjElem,pigMent);
		setCCbldSty2(Samp,'bc',pigMent);
	}
	setCCbldSty2('colorpicker201','vs','hidden');
	setCCbldSty2('colorpicker201','ds','none');
}
function showColorGrid2(OBjElem,Sam)
{
	var objX=new Array('00','33','66','99','CC','FF');
	var c=0;
	var z='"'+OBjElem+'","'+Sam+'",""';
	var xl='"'+OBjElem+'","'+Sam+'","x"';
	var mid='';mid+='<table bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0" style="border:solid 0px #F0F0F0;padding:2px;"><tr>';mid+="<td colspan='20' align='left' style='font-size:10px;background:#6666CC;color:#FFA;font-family:arial;'>Selection Palette</td></tr><tr><td colspan='18' align='center' style='margin:0;padding:2px;height:12px;' ><!--<input class='o5582n66' type='text' size='12' id='o5582n66' value='#FFFFFF'><input class='o5582n66a' type='text' size='2' style='width:14px;' id='o5582n66a' onclick='javascript:alert(\"click on selected swatch below...\");' value='' style='border:solid 1px #666;'>&nbsp;|-->&nbsp;<a class='o5582n66' href='javascript:onclick=putOBJxColor2("+z+")'><span class='a01p3'>"+nocol1+"</span></a>&nbsp;&nbsp;&nbsp;&nbsp;<a class='o5582n66' href='javascript:onclick=putOBJxColor2("+xl+")'><span class='a01p3'>"+clos1+"</span></a></td></tr><tr>";
	var br=1;
	for(o=0;o<6;o++){
		mid+='</tr><tr>';
		for(y=0;y<5;y++){
			if(y==3){
				mid+='</tr><tr>';
			}
			if(y==2)
				y++;
			for(x=0;x<5;x++){
				var grid='';grid=objX[o]+objX[y]+objX[x];
				var b="'"+OBjElem+"', '"+Sam+"','#"+grid+"'";
				mid+='<td class="o5582brd" style="background-color:#'+grid+'"><a class="o5582n66"  href="javascript:onclick=putOBJxColor2('+b+');" onmouseover=javascript:document.getElementById("o5582n66").value="#'+grid+'";javascript:document.getElementById("o5582n66a").style.backgroundColor="#'+grid+'";  title="#'+grid+'"><div style="width:12px;height:14px;"></div></a></td>';c++;
			}
		}
	}
				
				//mid+="</tr><!--<tr><td colspan='18' align='right' style='padding:2px;border:solid 1px #FFF;background:#FFF;'><a href='"+hm2+"' style='color:#666;font-size:8px;font-family:arial;text-decoration:none;letter-spacing:1px;'>"+tt2+"</a></td></tr>--></table>";
				mid +="</tr></table>";
				var ttop=getTop2();
				setCCbldSty2('colorpicker201','tp',ttop);
				document.getElementById('colorpicker201').style.left=getLeft2();
				setCCbldSty2('colorpicker201','vs','visible');
				setCCbldSty2('colorpicker201','ds','block');
				document.getElementById('colorpicker201').innerHTML=mid;
}




function showProofreadingOption(item_id)
{
	//alert(item_id);
	
	 var HTMLoutput = "";
	
	  myModalDialog = window.showModalDialog("resources/blank.htm", "" ,"dialogWidth:200px;dialogHeight:300px;help:no;status:no;");
	  alert(window.returnValue);
	
	 modalBody = myModalDialog.document.body;
	
	 modalBody.style.backgroundColor = "#ffcc33";
	
	 
	
	 HTMLoutput += "<html><head><title>Modal Dialog</title></head>";
	
	 HTMLoutput += "<body><h1>Important messages in this modal window</h1><br />";
	
	 HTMLoutput += "<form><div align='center'><input type='button' value='close' onclick='self.close();' />";
	
	 HTMLoutput +="</div></form></body></html>";
	
	
	
	 modalBody.innerHTML = HTMLoutput;


	
	//document.forms[0].action.value='remove_proofreading'; 
	//document.forms[0].item_id.value=item_id; 
	//document.forms[0].submit();	
}

dFeatures = 'dialogHeight: 250px; dialogWidth: 300px; dialogTop: 646px; edge: Raised; center: Yes; help: Yes; status: Yes;';//default features

modalWin = "null";
function xShowModalDialog( sURL, vArguments, sFeatures )
{
if (sURL==null||sURL=='')
{
alert ("Invalid URL input.");
return false;
}
if (vArguments==null||vArguments=='')
{
vArguments='';
}
if (sFeatures==null||sFeatures=='')
{
sFeatures=dFeatures;
}
alert("window.navigator.appVersion="+window.navigator.appVersion);
if (window.navigator.appVersion.indexOf("MSIE")!=-1)
{
window.showModalDialog ( sURL, vArguments, sFeatures );
return false;
}
sFeatures = sFeatures.replace(/ /gi,'');
aFeatures = sFeatures.split(";");
sWinFeat = "directories=0,menubar=0,titlebar=0,toolbar=0,";
for ( x in aFeatures )
{
aTmp = aFeatures[x].split(":");
sKey = aTmp[0].toLowerCase();
sVal = aTmp[1];
switch (sKey)
{
case "dialogheight":
sWinFeat += "height="+sVal+",";
pHeight = sVal;
break;
case "dialogwidth":
sWinFeat += "width="+sVal+",";
pWidth = sVal;
break;
case "dialogtop":
sWinFeat += "screenY="+sVal+",";
break;
case "dialogleft":
sWinFeat += "screenX="+sVal+",";
break;
case "resizable":
sWinFeat += "resizable="+sVal+",";
break;
case "status":
sWinFeat += "status="+sVal+",";
break;
case "center":
if ( sVal.toLowerCase() == "yes" )
{
sWinFeat += "screenY="+((screen.availHeight-pHeight)/2)+",";
sWinFeat += "screenX="+((screen.availWidth-pWidth)/2)+",";
}
break;
}
}
modalWin=window.open(String(sURL),"",sWinFeat);
if (vArguments!=null&&vArguments!='')
{
modalWin.dialogArguments=vArguments;
}
}

function checkFocus()
{
try{
if (window.navigator.appVersion.indexOf("MSIE")==-1)
{

if (modalWin!="null") 
{
if(!modalWin.closed){
self.blur();
modalWin.focus();

}
}
}
}catch(e){alert(e);}
}




function confirmDeleteLanguage(sourcelanguage_id, targetlanguage_id)
{
	if (window.confirm('Are you sure you want to delete this language combination?  \n If you do, you cannot add it back in to this project.'))
	{  
		document.forms[0].action.value='remove_language'; 
		document.forms[0].sourcelanguage_id.value=sourcelanguage_id; 
		document.forms[0].targetlanguage_id.value=targetlanguage_id; 
		document.forms[0].submit(); 
	}
}



//tools
var selectedSourceLanguage = new Array();
selectedSourceLanguage[0] = new Array('en', 'English', '0');
//selectedSourceLanguage[0] = new Array();

function removeSelectedSourcelanguageFromTargetLanguageList(sourcelanguageList)
{
	targetlanguageList = document.getElementById("targetlanguage_id");
	
	//addOption(targetlanguageList,selectedSourceLanguage[0][1],selectedSourceLanguage[0][0], selectedSourceLanguage[0][2]);	
	// replace individual existing entries
for (var i = 0; i < targetlanguageList.options.length; i++) {
	if(i == selectedSourceLanguage[0][2])
	{
		newOpt = document.createElement("OPTION");
		newOpt.text=selectedSourceLanguage[0][1];
		newOpt.value=selectedSourceLanguage[0][0];
		if (navigator.appName.toUpperCase().match(/MICROSOFT INTERNET EXPLORER/) != null)
			targetlanguageList.add(newOpt, selectedSourceLanguage[0][2]);
		if (navigator.appName.toUpperCase().match(/NETSCAPE/) != null)
			targetlanguageList.add(newOpt, targetlanguageList.options[i]);
	}
}
	
	for (i=0; i < sourcelanguageList.options.length; i++)
      if (sourcelanguageList.options[i].selected)
	  {
  	      selectedSourceLanguage[0][0] = sourcelanguageList.options[i].value;
		  selectedSourceLanguage[0][1] = sourcelanguageList.options[i].text;
		  selectedSourceLanguage[0][2] = i;
	  }


	for (i=0; i < targetlanguageList.options.length; i++)
      if (targetlanguageList.options[i].value == selectedSourceLanguage[0][0])
	  	targetlanguageList.remove(i);

	  	
}

function showSelected(menu)
 {
   document.forms[0].selected_targetlanguages.value="";
   
   var i, msg=""; err=true;
   
   for (i=0; i < menu.options.length; i++)
      if (menu.options[i].selected)
	  {
         document.forms[0].selected_targetlanguages.value += menu.options[i].value+",";
		 err = false;
	  }
	if(err)
		alert('Please select at least one target language!');
	else
	{
		source_lang = document.instant_quote_home.sourcelanguage_id.options[document.instant_quote_home.sourcelanguage_id.selectedIndex].value;
		if(document.forms[0].selected_targetlanguages.value.search(source_lang)!=-1)
			alert("You can not have same source and target language!")
		else
			document.forms[0].submit();
	}	
}  


//Add HTML controls
var arrInput = new Array(1);
  var arrInputValue = new Array(1);

function addInput() {
	if(arrInput.length <= 3)	
	{
	  arrInput.push(arrInput.length);
	  arrInputValue.push("");
	  display();
	}
	else
	{
		document.getElementById("email_coleague").href="#";
		document.getElementById("email_coleague").style.color="grey";
	}
}

function display() {
  document.getElementById('parah').innerHTML="";
  for (intI=1;intI<arrInput.length;intI++) {
    document.getElementById('parah').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);
  }
}

function saveValue(intId,strValue) {
  arrInputValue[intId]=strValue;
}  

function createInput(id,value) {
  return '<tr> <td width="100">Name: </td><td><input type="text" name="name_'+id+'" id="name_'+id+'" onChange="javascript:saveValue('+ id +',this.value)" value="'+ value +'"/></td></tr> <tr> <td>Email: </td><td><input type="text" name="email_'+id+'" id="email_'+id+'" onChange="javascript:saveValue('+ id +',this.value)" value="'+ value +'" /></td></tr><br/>';
  
  
  //<input type='text' id='test "+ id +"' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'></td><td>Email:</td>";
}

function deleteInput() {
  if (arrInput.length > 0) { 
     arrInput.pop(); 
     arrInputValue.pop();
  }
  display(); 
}
///

//rigurous email validation
function validEmail(email_value)
{
emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
if (!emailRe.test(email_value))
	return false;
else 
	return true;
	
}

//simple email validation
function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 
}
function isFreeEmailAddress(email_value)
{
	emailRe = /\@yahoo|\@hotmail|\@gmail/;
	if (!emailRe.test(email_value))
		return false;
	else 
		return true;
}

function validateInstantQuote() {
	if(validEmail(document.instant_quote_home.email.value))	{
		 if(isFreeEmailAddress(document.instant_quote_home.email.value))
		     alert('It looks like you\'ve tried to generate a quote with a free web-based email address. Please use your company email address. If you are not part of a company, we\'re sorry but we won\'t be able to serve you');   
		 else
		 	showSelected(document.instant_quote_home.targetlanguage_id);
	} 
	else { alert('Your email address is incorrect!'); document.instant_quote_home.email.focus();}
}


function makeSum()
{
	total_quantity = 0;
	intRe = /^\d+$/;
	
	//validate if the value is a number
	input_elements = document.getElementsByTagName("input");
	for(i=0; i<input_elements.length; i++)
	{
		if ((input_elements[i].id) && (input_elements[i].id.substr(0, 9)  == 'quantity_') &&  intRe.test(input_elements[i].value))	
		{
			total_quantity += parseInt(input_elements[i].value);
		}
	}
	document.forms[0].quantity.value=total_quantity;
	
	
	
}