// JavaScript Document

function trimStr(str){	
    while(str.charAt(0) == (" ") ){
	    str = str.substring(1);	
    }
    while(str.charAt(str.length-1) == " " ){
	   str = str.substring(0,str.length-1);	
    }	
    return str;
}

function codeStr(str){	
    // Create Array of Specicl Characters
    var chars = new Array();    
    // German Characters
    chars["Ä"] = "&Auml;";
    chars["ä"] = "&auml;";  
    chars["Ö"] = "&Ouml;"; 
    chars["ö"] = "&ouml;"; 
    chars["Ü"] = "&Uuml;"; 
    chars["ü"] = "&uuml;"; 
    chars["ß"] = "&szlig;"; 
    // French Characters
    chars["À"] = "&Agrave;"; 
    chars["à"] = "&agrave;";  
    chars["Â"] = "&Acirc;";
    chars["â"] = "&acirc;"; 
    chars["Ç"] = "&Ccedil;"; 
    chars["ç"] = "&ccedil;"; 
    chars["È"] = "&Egrave;"; 
    chars["è"] = "&egrave;"; 
    chars["É"] = "&Eacute;"; 
    chars["é"] = "&eacute;"; 
    chars["Ê"] = "&Ecirc;"; 
    chars["ê"] = "&ecirc;"; 
    chars["Ë"] = "&Euml;"; 
    chars["ë"] = "&euml;"; 
    chars["Î"] = "&Icirc;"; 
    chars["î"] = "&icirc;"; 
    chars["Ï"] = "&Iuml;"; 
    chars["ï"] = "&iuml;"; 
    chars["Ô"] = "&Ocirc;"; 
    chars["ô"] = "&ocirc;"; 
    chars["Œ"] = "&OElig;"; 
    chars["œ"] = "&oelig;"; 
    chars["Ù"] = "&Ugrave;"; 
    chars["ù"] = "&ugrave;"; 
    chars["Û"] = "&Ucirc;"; 
    chars["û"] = "&ucirc;"; 
    chars["Ü"] = "&Uuml;"; 
    chars["ü"] = "&uuml;"; 
    chars["Ÿ"] = "&#376;"; 
    chars["ÿ"] = "&yuml;";
    // Greek Characters
    chars["µ"] = "&mu;";         
    // Other Special Character
    chars["®"] = "&reg;";
    chars["©"] = "&copy;";
    chars["€"] = "&euro;";
    chars["™"] = "&trade;"; 
    chars["°"] = "&deg;";         
    for (var c in chars) {
        str = str.replace( new RegExp(c,"g"), chars[c]);            
    }   
    return str;
                     
}


function checkCase(){    
	if (trimStr(document.update.ref.value).length < 5){
	    alert("Please provide 5 character Reference!");
	    document.update.ref.focus();
	    document.update.ref.select();
	    return false;	
	}
	if (document.update.title.value == ""){
	    alert("Please provide a Title");
	    document.update.title.focus();
	    return false;	
	}
	
	document.update.title.value = codeStr(document.update.title.value);	
	document.update.description.value = codeStr(document.update.description.value);		
		
	return true;			
}

function deleteCase(id){
    if (confirm("Delete this Case Study Permanently?")){
        window.location = "all-delete.asp?rec=case&id=" + id    
    }  	
}

function checkIndustry(){    	
	if (document.update.title.value == ""){
	    alert("Please provide an Industry Name");
	    document.update.title.focus();
	    return false;	
	}
	return true;			
}

function deleteIndustry(id){
    if (confirm("Delete this Industry Permanently?")){
        window.location = "all-delete.asp?rec=industry&id=" + id    
    }  	
}

function deleteRegion(id){
    if (confirm("Delete this Region Permanently?")){
        window.location = "all-delete.asp?rec=region&id=" + id    
    }  	
}
function checkRegion(){    	
	if (document.update.title.value == ""){
	    alert("Please provide an Region Name");
	    document.update.title.focus();
	    return false;	
	}
	return true;			
}

function deleteContact(id){
    if (confirm("Delete this Contact Permanently?")){
        window.location = "all-delete.asp?rec=contact&id=" + id    
    }  	
}
function checkContact(){ 
	   	
	if (document.update.editor1.value == ""){
	    alert("Please provide Contact Details");
	    document.update.editor1.focus();
	    return false;	
	}
	return true;			
}

function checkNews(){ 
	
	if (document.update.title.value == ""){
	    alert("Please provide a Title");
	    document.update.title.focus();
	    return false;	
	}
	if ((document.update.download.value == "") && (document.update.files.value == "0")){
	    alert("Please provide a Download");
	    document.update.download.focus();
	    return false;	
	}
	
	document.update.title.value = codeStr(document.update.title.value);	
	document.update.description.value = codeStr(document.update.description.value);		
		
	return true;			
}

function deleteNews(id){
    if (confirm("Delete this News Story Permanently?")){
        window.location = "all-delete.asp?rec=news&id=" + id    
    }  	
}

function checkShow(){    
	if (trimStr(document.update.start_date.value) == ""){
	    alert("Please select a Start Date!");
	    document.update.start_date.focus();
	    document.update.start_date.select();
	    return false;	
	}
	if (trimStr(document.update.end_date.value) == ""){
	    alert("Please select an End Date!");
	    document.update.end_date.focus();
	    document.update.end_date.select();
	    return false;	
	}	
	if (document.update.type.value == ""){
	    alert("Please select an Industry!");
	    document.update.type.focus();
	    return false;	
	}	
	if (trimStr(document.update.title.value) == ""){
	    alert("Please provide a Title");
	    document.update.title.focus();
	    return false;	
	}
	if (trimStr(document.update.description.value) == ""){
	    alert("Please provide a Location");
	    document.update.description.focus();
	    return false;	
	}	
	return true;	
	
	document.update.ref.value = codeStr(document.update.ref.value);
    document.update.description.value = codeStr(document.update.description.value);	
	document.update.title.value = codeStr(document.update.title.value);	
				
}

function deleteShow(id){
    if (confirm("Delete this Show/Event Permanently?")){
        window.location = "all-delete.asp?rec=show&id=" + id    
    }  	   
}

function checkCourse(){    
	if (trimStr(document.update.start_date.value) == ""){
	    alert("Please select a Start Date!");
	    document.update.start_date.focus();
	    document.update.start_date.select();
	    return false;	
	}
	if (trimStr(document.update.end_date.value) == ""){
	    alert("Please select an End Date!");
	    document.update.end_date.focus();
	    document.update.end_date.select();
	    return false;	
	}	
	if (document.update.type.value == ""){
	    alert("Please select an Industry!");
	    document.update.type.focus();
	    return false;	
	}	
	if (document.update.title.value == ""){
	    alert("Please provide a Title");
	    document.update.title.focus();
	    return false;	
	}
	if (document.update.ref.value == ""){
	    alert("Please provide a Location");
	    document.update.ref.focus();
	    return false;	
	}
	
	document.update.ref.value = codeStr(document.update.ref.value);
    document.update.description.value = codeStr(document.update.description.value);	
	document.update.title.value = codeStr(document.update.title.value);	
		
	return true;			
}

function deleteCourse(id){
    if (confirm("Delete this Training Course Permanently?")){
        window.location = "all-delete.asp?rec=course&id=" + id    
    }  	   
}

function deletePage(id, sec){
    if (confirm("Delete this Page Permanently?")){
        window.location = "all-delete.asp?rec=page&id=" + id + "&sec=" + sec    	
    }  	  
}

function checkProduct(){ 
	if (document.update.title.value == ""){
	    alert("Please provide a Product Name");
	    document.update.title.focus();
	    return false;	
	}
	if (document.update.page_link.value == ""){
	    alert("Please select a Product Page");
	    document.update.page_link.focus();
	    return false;	
	}	
	if ((document.update.thumbnail.value == "") && (document.update.files.value == "0")){
	    alert("Please provide a Thumbnail");
	    document.update.thumbnail.focus();
	    return false;	
	}	

	document.update.title.value = codeStr(document.update.title.value);	
	document.update.description.value = codeStr(document.update.description.value);	
    
	return true;			
}

function deleteProduct(id){
    if (confirm("Delete this Product Permanently?")){
        window.location = "all-delete.asp?rec=product&id=" + id
    }  	  
}

function checkImage(){
	if (document.update.image.value == ""){
	    alert("Please select an Image");
	    document.update.image.focus();
	    return false;	
	}	
	return true;    	
}

function deleteImage(file){
    if (confirm("Delete this Image Permanently?")){
        window.location = "library-update.asp?img=" + file
    }  	  
}

function previewPage(id){
    window.open('../ppe-page.asp?id=' + id + '&mode=cms','preview','width=1024,height=768,toolbar=yes, location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no, resizable=yes')	
}

function previewSubPage(ref){
    window.open('../' + ref + '.asp?mode=cms','preview','width=1024,height=768,toolbar=yes, location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no, resizable=yes')	
}

function previewMenu(id){
    window.open('../index.asp','preview','width=1024,height=768,toolbar=yes, location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no, resizable=yes')	
}

function checkSubPage(){	    

	if (trimStr(document.update.menu.value) == ""){
	    alert("Please provide Page Menu Text!");
	    document.update.menu.focus();
	    return false;	
	}	    		
	if (trimStr(document.update.title.value) == ""){
	    alert("Please provide a Page Title!");
	    document.update.title.focus();
	    return false;	
	}
	if (trimStr(document.update.header1.value) == ""){
	    alert("Please provide a Main Heading!");
	    document.update.header1.focus();
	    return false;	
	}
	
if ((document.update.ref.value == "index")||(document.update.ref.value == "login_ch")){

	document.update.top_alt.value = codeStr(document.update.top_alt.value);
		
}else{
	
	document.update.menu_text.value = codeStr(document.update.menu_text.value);
	document.update.menu_tool.value = codeStr(document.update.menu_tool.value);	
	document.update.pdf_text.value = codeStr(document.update.pdf_text.value);
	document.update.pdf_tool.value = codeStr(document.update.pdf_tool.value);
	document.update.web_text.value = codeStr(document.update.web_text.value);		
	    	
	// Check for New Link
	if ((document.update.menu_link.value != "") && (trimStr(document.update.menu_text.value) == "")){
	    alert("Please provide Text for New Menu Link!");
	    document.update.menu_text.focus();
	    return false;			
	}
	
	// Check for New PDF Link
	if ((document.update.pdf.value != "") && (trimStr(document.update.pdf_text.value) == "")){
	    alert("Please provide Text for New PDF Link!");
	    document.update.pdf_text.focus();
	    return false;			
	}	
	
	// Check for New Web Link
	if ((document.update.web_link.value != "") && (trimStr(document.update.web_text.value) == "")){
	    alert("Please provide Text for New Weblink!");
	    document.update.web_text.focus();
	    return false;			
	}		

}	
	
	// Convert Foriegn Characters
	document.update.menu.value = codeStr(document.update.menu.value);		
	document.update.title.value = codeStr(document.update.title.value);		
	document.update.description.value = codeStr(document.update.description.value);
	document.update.keywords.value = codeStr(document.update.keywords.value);
	document.update.header1.value = codeStr(document.update.header1.value);
		
			
	return true;
} 

// Check Brochure
function checkBrochure(){ 
	
	if (document.update.title.value == ""){
	    alert("Please provide a Title");
	    document.update.title.focus();
	    return false;	
	}
	if (document.update.description.value == ""){
	    alert("Please provide a Description");
	    document.update.description.focus();
	    return false;	
	}	
	if ((document.update.thumbnail.value == "") && (document.update.thumb.value == "0")){
	    alert("Please provide a Thumbnail");
	    document.update.thumbnail.focus();
	    return false;	
	}	
	if ((document.update.download.value == "") && (document.update.files.value == "0")){
	    alert("Please provide a Download");
	    document.update.download.focus();
	    return false;	
	}	
	
	document.update.title.value = codeStr(document.update.title.value);	
	document.update.description.value = codeStr(document.update.description.value);		
		
	return true;			
}

function deleteBrochure(id){
    if (confirm("Delete this Brochure Permanently?")){
        window.location = "all-delete.asp?rec=brochure&id=" + id
    }  	  
}

function checkPageNew(){
	
	if (trimStr(document.update.sec.value) == ""){
	    alert("Please select a Section!");
	    document.update.sec.focus();
	    return false;	
	}	
    if (trimStr(document.update.ref.value) == ""){
	    alert("Please provide a CMS Page Name!");
	    document.update.ref.focus();
	    return false;	
	}else{
	    if(checkDuplicates('ref',trimStr(document.update.ref.value),document.update.id.value) == false){
            alert("CMS Page Name already exists in this site!");
	        document.update.ref.focus();              
		    return false;  		    
	    }  	
	}	
    if (trimStr(document.update.link.value) == ""){
	    alert("Please provide SEO Link Text!");
	    document.update.link.focus();
	    return false;	
	}else{
		if (!checkCharacters(trimStr(escape(document.update.link.value)))) {
            alert("SEO Link Text can only contain normal letters, numbers, single spaces and hyphens!");
	        document.update.link.focus();              
		    return false;			
	    }else{
	        if(!checkDuplicates('link',trimStr(document.update.link.value),document.update.id.value)){
                alert("SEO Link Text already exists in this site!");
	            document.update.link.focus();              
		        return false;
	        }     		    
	    } 	
	}
	if (trimStr(document.update.menu.value) == ""){
	    alert("Please provide Page Menu Text!");
	    document.update.menu.focus();
	    return false;	
	}		
	if (trimStr(document.update.title.value) == ""){
	    alert("Please provide a Page Title!");
	    document.update.title.focus();
	    return false;	
	}
	if (trimStr(document.update.header1.value) == ""){
	    alert("Please provide a Main Heading!");
	    document.update.header1.focus();
	    return false;	
	}
	
	// Check for New Link
	if ((document.update.menu_link.value != "") && (trimStr(document.update.menu_text.value) == "")){
	    alert("Please provide Text for New Menu Link!");
	    document.update.menu_text.focus();
	    return false;			
	}
	
	// Check for New PDF Link
	if ((document.update.pdf.value != "") && (trimStr(document.update.pdf_text.value) == "")){
	    alert("Please provide Text for New PDF Link!");
	    document.update.pdf_text.focus();
	    return false;			
	}	
	
	// Check for New Web Link
	if ((document.update.web_link.value != "") && (trimStr(document.update.web_text.value) == "")){
	    alert("Please provide Text for New Weblink!");
	    document.update.web_text.focus();
	    return false;			
	}	

	// Convert Foriegn Characters
	document.update.ref.value = codeStr(document.update.ref.value);
	document.update.title.value = codeStr(document.update.title.value);
	
	document.update.top_alt.value = codeStr(document.update.top_alt.value);
	document.update.img_alt.value = codeStr(document.update.img_alt.value);	
	
	document.update.menu.value = codeStr(document.update.menu.value);
	document.update.menu_text.value = codeStr(document.update.menu_text.value);
	document.update.menu_tool.value = codeStr(document.update.menu_tool.value);	
	document.update.pdf_text.value = codeStr(document.update.pdf_text.value);
	document.update.pdf_tool.value = codeStr(document.update.pdf_tool.value);
	document.update.web_text.value = codeStr(document.update.web_text.value);			
	document.update.link.value = codeStr(document.update.link.value);		
	document.update.description.value = codeStr(document.update.description.value);
	document.update.keywords.value = codeStr(document.update.keywords.value);
	document.update.header1.value = codeStr(document.update.header1.value);
	document.update.menu_head.value = codeStr(document.update.menu_head.value);		
			
	return true;
} 

function checkTabs(){
	
    for(i=0; i<document.update.elements.length; i++)
    {
        if (trimStr(document.update.elements[i].value) == ""){
	        alert("Please provide Text and Links for all Tabs!"); 
	        return false;   
        } else {
	        document.update.elements[i].value = codeStr(document.update.elements[i].value);    
        }
    }

    return true;	
		
}

function checkTabsMenu(){
	
	// Check for New Link
	if ((document.update.menu_link.value != "") && (trimStr(document.update.menu_text.value) == "")){
	    alert("Please provide Text for New Menu Link!");
	    document.update.menu_text.focus();
	    return false;			
	}

    return true;	
		
}

function copyPage(id){
	
	// Check for target
	if (trimStr(document.update.copy_page.value) == ""){
	    alert("Please select a website to Copy Page to!");
	    document.update.copy_page.focus();
	    return false;			
	}
	
	var str = document.update.copy_page.value;
	var arr = str.split('-');
    window.location = 'page-open.asp?id=0&src=' + id + 	'&lang=' + arr[1] + '&site=' + arr[0];

    return true;		
	
}

