﻿function ShowModalDialog(url, width, height)
    {
	    //url = url + "?dummy=" + Math.random();
	    if(window.showModalDialog)
	    {
		    result = window.showModalDialog(url, window.self, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;status:no;help:no;scroll:auto");
		}
	    else
	    {
		    var dialog = window.open(url, "_blank", "width=" + width + ",height=" + height + ",left=" + ((screen.availWidth - width)/2) + ",top=100,toolbar=no,status=no,scrollbars=auto,resizable=no,modal=yes");
		    dialog.dialogArguments = window.self;
	    }
    }

function reloadParentWindow()
{
    if(window.dialogArguments)
    {
        window.dialogArguments.document.location.reload();
    }
    else
    {
        opener.document.location.reload();
    }
}

function InsertImage(id)
{
    var imgObject = document.getElementById(id);
    for(i=0; i<window.opener.document.forms[0].elements.length;i++)
    {
        if(window.opener.document.forms[0].elements[i].type == 'textarea' && window.opener.document.forms[0].elements[i].name.indexOf('txtEmailTo')==-1)
        {
            var htmlEditor = window.opener.document.forms[0].elements[i];
            htmlEditor.document.focus();
            htmlEditor.document.execCommand('insertimage', false, imgObject.src.replace("http://ksasale.com", "http://www.ksasale.com"));
            htmlEditor.document.focus();
            window.close();
        }
    }
}
    //prototype function to trim string 
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
// function does the same but not a prototype
function trim(s)
{
    var l=0; var r=s.length -1;
    while(l < s.length && s[l] == ' ')
    {     l++; }
    while(r > l && s[r] == ' ')
    {     r-=1;     }
    return s.substring(l, r+1);
} 
// function to check e-mail validation
function isEmail(string) 
{
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
    {
       return true;
    }
    else
    {
       return false;
    }
}